diff --git a/.github/workflows/index.yml b/.github/workflows/index.yml index f2246ef..bf0968e 100644 --- a/.github/workflows/index.yml +++ b/.github/workflows/index.yml @@ -9,11 +9,11 @@ jobs: - name: Clone environment uses: actions/checkout@v1 - name: Set up environment - uses: docker://alpine:3.10 + uses: docker://alpine:edge with: args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && composer global require hirak/prestissimo && composer install -o --no-ansi --no-suggest" - name: Code Style Checker - uses: docker://alpine:3.10 + uses: docker://alpine:edge with: args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && vendor/bin/phpcs bin src tests -p --ignore=tests/*/Data/* --extensions=php --standard=ruleset.xml" codeStaticAnalysis: @@ -23,11 +23,11 @@ jobs: - name: Clone environment uses: actions/checkout@v1 - name: Set up environment - uses: docker://alpine:3.10 + uses: docker://alpine:edge with: args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && composer global require hirak/prestissimo && composer install -o --no-ansi --no-suggest" - name: Code Static Analysis - uses: docker://alpine:3.10 + uses: docker://alpine:edge with: args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && vendor/bin/phpstan analyse bin src tests -c ruleset.neon -l 7" integrationTest: @@ -37,13 +37,13 @@ jobs: - name: Clone environment uses: actions/checkout@v1 - name: Set up environment - uses: docker://alpine:3.10 + uses: docker://alpine:edge with: args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && composer global require hirak/prestissimo && composer install -o --no-ansi --no-suggest" - name: Integration Test - uses: docker://alpine:3.10 + uses: docker://alpine:edge with: - args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && vendor/bin/phpunit tests" + args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && vendor/bin/phpunit tests && chmod +x bin/phpunit-coverage-analyzer && bin/phpunit-coverage-analyzer" infectionTest: name: Infection Test runs-on: ubuntu-latest @@ -51,10 +51,10 @@ jobs: - name: Clone environment uses: actions/checkout@v1 - name: Set up environment - uses: docker://alpine:3.10 + uses: docker://alpine:edge with: args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && composer global require hirak/prestissimo && composer install -o --no-ansi --no-suggest" - name: Infection Test - uses: docker://alpine:3.10 + uses: docker://alpine:edge with: args: /bin/sh -c "apk update && apk upgrade && apk add composer php7-curl php7-dom php7-pdo php7-simplexml php7-tokenizer php7-xml php7-xmlwriter && apk add php7-pecl-pcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing && export INFECTION=INFECTION && vendor/bin/infection -j8 --only-covered --no-ansi && export INFECTION" \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 7dad910..2310ad2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,20 +1,19 @@ language: php php: - - 7.2 - - 7.3 + - 7.4 before_script: - pecl install pcov - phpenv config-rm xdebug.ini - composer global require hirak/prestissimo -o --no-ansi --no-suggest - composer install -o --no-ansi --no-suggest - - vendor/bin/phpunit tests script: - - vendor/bin/phpcs bin src tests -p --ignore=tests/*/Data/* --extensions=php --standard=ruleset.xml - - vendor/bin/phpstan analyse bin src tests -c ruleset.neon -l 7 + - vendor/bin/phpcs bin src tests --ignore=Data --standard=ruleset.xml + - vendor/bin/phpstan analyse bin src tests -c ruleset.neon -l 8 --error-format custom - vendor/bin/phpunit tests --coverage-clover build/logs/clover.xml + - chmod +x bin/phpunit-coverage-analyzer && bin/phpunit-coverage-analyzer - export INFECTION=INFECTION && vendor/bin/infection -j8 --coverage=var/coverage --only-covered --no-ansi && export INFECTION after_success: diff --git a/bin/phpunit-coverage-analyzer b/bin/phpunit-coverage-analyzer new file mode 100755 index 0000000..e22bba5 --- /dev/null +++ b/bin/phpunit-coverage-analyzer @@ -0,0 +1,8 @@ +#!/usr/bin/env php +tests - - + + + + + + src - - + + - - - + - - - \ No newline at end of file diff --git a/ruleset.neon b/ruleset.neon index b7bdb16..043e017 100644 --- a/ruleset.neon +++ b/ruleset.neon @@ -8,7 +8,13 @@ includes: - ./vendor/phpstan/phpstan-strict-rules/rules.neon - ./vendor/phpstan/phpstan-deprecation-rules/rules.neon +services: + errorFormatter.custom: + factory: Bruha\CodingStandard\CustomReports\PhpStanReport + parameters: + excludes_analyse: + - tests/*/Data/* ignoreErrors: - '#Constant T_ANON_CLASS not found#' - '#Constant T_DOC_COMMENT_CLOSE_TAG not found#' @@ -16,6 +22,5 @@ parameters: - '#Constant T_DOC_COMMENT_STRING not found#' - '#Constant T_DOC_COMMENT_TAG not found#' - '#Constant T_DOC_COMMENT_WHITESPACE not found#' - - '#Constant T_PARENT not found#' - - '#Constant T_SEMICOLON not found#' - - '#Constant T_STRING_CONCAT not found#' \ No newline at end of file + - '#Constant T_STRING_CONCAT not found#' + - '#Expression ".+" on a separate line does not do anything#' \ No newline at end of file diff --git a/ruleset.xml b/ruleset.xml index 9a2d372..14d7aa1 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,5 +1,9 @@ + + + + @@ -10,6 +14,7 @@ + @@ -82,23 +87,33 @@ + + + + - + + + + + + + @@ -110,7 +125,7 @@ - + @@ -150,24 +165,6 @@ - - - - - - - - - - - - - - - - - - @@ -187,6 +184,15 @@ + + + + + + + + + diff --git a/src/CustomHooks/PhpUnitHook.php b/src/CustomHooks/PhpUnitHook.php index 1d7fdd3..ecdab7d 100644 --- a/src/CustomHooks/PhpUnitHook.php +++ b/src/CustomHooks/PhpUnitHook.php @@ -16,19 +16,19 @@ final class PhpUnitHook implements BeforeTestHook, AfterTestHook, AfterLastTestH { /** - * @var array + * @var mixed[] */ - private $tests = []; + private array $tests = []; /** * @var float */ - private $time = 0.0; + private float $time = 0.0; /** * @var int */ - private $count = 0; + private int $count = 0; /** * @param string $test diff --git a/src/CustomPatches/DoctrineAnnotationOne.patch b/src/CustomPatches/DoctrineAnnotationOne.patch deleted file mode 100644 index d933001..0000000 --- a/src/CustomPatches/DoctrineAnnotationOne.patch +++ /dev/null @@ -1,14 +0,0 @@ ---- project/vendor/stesie/phpcs-doctrine-annotation-rules/src/DoctrineAnnotationCodingStandard/Sniffs/Commenting/AbstractDoctrineAnnotationSniff.php (date 1286705410000) -+++ project/vendor/stesie/phpcs-doctrine-annotation-rules/src/DoctrineAnnotationCodingStandard/Sniffs/Commenting/AbstractDoctrineAnnotationSniff.php (date 1286705410000) -@@ -220,12 +220,6 @@ - $stackPtr++; - } - -- if ($tokens[$stackPtr]['type'] !== 'T_SEMICOLON') { -- throw new ParseErrorException( -- \sprintf('Parse error on line %d: after T_USE, T_SEMICOLON expected', $tokens[$stackPtr]['line']) -- ); -- } -- - $this->imports->add($alias, $use); - } diff --git a/src/CustomPatches/DoctrineAnnotationTwo.patch b/src/CustomPatches/DoctrineAnnotationTwo.patch deleted file mode 100644 index b558dad..0000000 --- a/src/CustomPatches/DoctrineAnnotationTwo.patch +++ /dev/null @@ -1,14 +0,0 @@ ---- project/vendor/stesie/phpcs-doctrine-annotation-rules/src/DoctrineAnnotationCodingStandard/Helper/TypeHelper.php (date 1286705410000) -+++ project/vendor/stesie/phpcs-doctrine-annotation-rules/src/DoctrineAnnotationCodingStandard/Helper/TypeHelper.php (date 1286705410000) -@@ -28,9 +28,9 @@ - return self::convertPrimitiveType($varTagContent, $namespace, $classMap); - } - -- if (in_array('null', $parts)) { -+ if (in_array('NULL', $parts)) { - $parts = array_filter($parts, function (string $value) { -- return $value !== 'null'; -+ return $value !== 'NULL'; - }); - return new NullableType(self::fromString(implode('|', $parts), $namespace, $classMap)); - } diff --git a/src/CustomPatches/PHPCodeSnifferOne.patch b/src/CustomPatches/PHPCodeSnifferOne.patch deleted file mode 100644 index 4e211d4..0000000 --- a/src/CustomPatches/PHPCodeSnifferOne.patch +++ /dev/null @@ -1,54 +0,0 @@ ---- project/vendor/squizlabs/php_codesniffer/src/Runner.php (date 1286705410000) -+++ project/vendor/squizlabs/php_codesniffer/src/Runner.php (date 1286705410000) -@@ -123,9 +123,8 @@ - // print the timer info. - if ($this->config->interactive === false - && ($toScreen === false -- || (($this->reporter->totalErrors + $this->reporter->totalWarnings) === 0 && $this->config->showProgress === true)) -+ || (($this->reporter->totalErrors + $this->reporter->totalWarnings) === 0 && $this->config->showProgress === true)) - ) { -- Util\Timing::printRunTime(); - } - } catch (DeepExitException $e) { - echo $e->getMessage(); -@@ -193,8 +192,6 @@ - $this->run(); - $this->reporter->printReports(); - -- echo PHP_EOL; -- Util\Timing::printRunTime(); - } catch (DeepExitException $e) { - echo $e->getMessage(); - return $e->getCode(); -@@ -508,7 +505,7 @@ - && $this->config->interactive === false - && $this->config->showProgress === true - ) { -- echo PHP_EOL.PHP_EOL; -+ echo PHP_EOL; - } - - if ($this->config->cache === true) { -@@ -810,18 +807,18 @@ - }//end if - }//end if - -- $numPerLine = 60; -+ $numPerLine = 50; - if ($numProcessed !== $numFiles && ($numProcessed % $numPerLine) !== 0) { - return; - } - -- $percent = round(($numProcessed / $numFiles) * 100); -- $padding = (strlen($numFiles) - strlen($numProcessed)); -- if ($numProcessed === $numFiles && $numFiles > $numPerLine) { -+ $percent = str_pad(round($numProcessed / $numFiles * 100), 3, ' ', STR_PAD_LEFT); -+ $padding = strlen($numFiles) - strlen($numProcessed); -+ if ($numProcessed === $numFiles) { - $padding += ($numPerLine - ($numFiles - (floor($numFiles / $numPerLine) * $numPerLine))); - } - -- echo str_repeat(' ', $padding)." $numProcessed / $numFiles ($percent%)".PHP_EOL; -+ echo str_repeat(' ', $padding) . " $numProcessed / $numFiles ($percent%)" . ($numProcessed === $numFiles ? '' : PHP_EOL); - - }//end printProgress() diff --git a/src/CustomPatches/PHPCodeSnifferTwo.patch b/src/CustomPatches/PHPCodeSnifferTwo.patch deleted file mode 100644 index e6111da..0000000 --- a/src/CustomPatches/PHPCodeSnifferTwo.patch +++ /dev/null @@ -1,34 +0,0 @@ ---- project/vendor/squizlabs/php_codesniffer/src/Reports/Full.php (date 1286705410000) -+++ project/vendor/squizlabs/php_codesniffer/src/Reports/Full.php (date 1286705410000) -@@ -74,7 +74,7 @@ - } - } - -- $file = $report['filename']; -+ $file = str_replace(getcwd(), '', $report['filename']); - $fileLength = strlen($file); - $maxWidth = max(($fileLength + 6), ($maxErrorLength + $paddingLength)); - $width = min($width, $maxWidth); -@@ -164,12 +164,7 @@ - }//end foreach - - echo str_repeat('-', $width).PHP_EOL; -- if ($report['fixable'] > 0) { -- echo "\033[1m".'PHPCBF CAN FIX THE '.$report['fixable'].' MARKED SNIFF VIOLATIONS AUTOMATICALLY'."\033[0m".PHP_EOL; -- echo str_repeat('-', $width).PHP_EOL; -- } - -- echo PHP_EOL; - return true; - - }//end generateFileReport() -@@ -207,11 +202,6 @@ - } - - echo $cachedData; -- -- if ($toScreen === true && $interactive === false) { -- Util\Timing::printRunTime(); -- } -- - }//end generate() diff --git a/src/CustomPatches/PHPInfectionEight.patch b/src/CustomPatches/PHPInfectionEight.patch deleted file mode 100644 index 7a03e65..0000000 --- a/src/CustomPatches/PHPInfectionEight.patch +++ /dev/null @@ -1,13 +0,0 @@ ---- project/vendor/infection/infection/src/Process/Listener/MutationTestingResultsLoggerSubscriber.php (date 1286705410000) -+++ project/vendor/infection/infection/src/Process/Listener/MutationTestingResultsLoggerSubscriber.php (date 1286705410000) -@@ -77,9 +77,7 @@ - - public function getSubscribedEvents(): array - { -- return [ -- MutationTestingFinished::class => [$this, 'onMutationTestingFinished'], -- ]; -+ return []; - } - - public function onMutationTestingFinished(MutationTestingFinished $event): void diff --git a/src/CustomPatches/PHPInfectionFive.patch b/src/CustomPatches/PHPInfectionFive.patch deleted file mode 100644 index 89976e4..0000000 --- a/src/CustomPatches/PHPInfectionFive.patch +++ /dev/null @@ -1,59 +0,0 @@ ---- project/vendor/infection/infection/src/Process/Listener/MutantCreatingConsoleLoggerSubscriber.php (date 1286705410000) -+++ project/vendor/infection/infection/src/Process/Listener/MutantCreatingConsoleLoggerSubscriber.php (date 1286705410000) -@@ -40,6 +40,7 @@ - use Infection\Events\MutantsCreatingFinished; - use Infection\Events\MutantsCreatingStarted; - use Symfony\Component\Console\Helper\ProgressBar; -+use Symfony\Component\Console\Output\NullOutput; - use Symfony\Component\Console\Output\OutputInterface; - - /** -@@ -57,11 +58,16 @@ - */ - private $progressBar; - -+ /** -+ * @var int -+ */ -+ private $counter = 1; -+ - public function __construct(OutputInterface $output) - { - $this->output = $output; - -- $this->progressBar = new ProgressBar($this->output); -+ $this->progressBar = new ProgressBar(new NullOutput()); - $this->progressBar->setFormat('Creating mutated files and processes: %current%/%max%'); - } - -@@ -76,12 +82,30 @@ - - public function onMutantsCreatingStarted(MutantsCreatingStarted $event): void - { -- $this->output->writeln(['']); -+ echo PHP_EOL; - $this->progressBar->start($event->getMutantCount()); - } - - public function onMutantCreated(MutantCreated $event): void - { -+ $numberLength = max(3, strlen((string) $this->progressBar->getMaxSteps())); -+ $maximumWidth = 50; -+ -+ $message = sprintf( -+ sprintf(' %%%sd / %%%sd (%%3d%%%%)', $numberLength, $numberLength), -+ $this->counter, -+ $this->progressBar->getMaxSteps(), -+ round(($this->counter / $this->progressBar->getMaxSteps()) * 100) -+ ); -+ -+ echo '.'; -+ echo $this->counter % $maximumWidth === 0 ? sprintf('%s%s', $message, PHP_EOL) : ''; -+ -+ if ($this->progressBar->getMaxSteps() == $this->counter) { -+ echo sprintf('%s%s%s', str_repeat(' ', $maximumWidth - $this->counter % $maximumWidth), $message, PHP_EOL); -+ } -+ -+ $this->counter++; - $this->progressBar->advance(); - } diff --git a/src/CustomPatches/PHPInfectionFour.patch b/src/CustomPatches/PHPInfectionFour.patch deleted file mode 100644 index c820a54..0000000 --- a/src/CustomPatches/PHPInfectionFour.patch +++ /dev/null @@ -1,15 +0,0 @@ ---- project/vendor/infection/infection/src/Process/Listener/InitialTestsConsoleLoggerSubscriber.php (date 1286705410000) -+++ project/vendor/infection/infection/src/Process/Listener/InitialTestsConsoleLoggerSubscriber.php (date 1286705410000) -@@ -48,11 +48,7 @@ - - public function getSubscribedEvents(): array - { -- return [ -- InitialTestSuiteStarted::class => [$this, 'onInitialTestSuiteStarted'], -- InitialTestSuiteFinished::class => [$this, 'onInitialTestSuiteFinished'], -- InitialTestCaseCompleted::class => [$this, 'onInitialTestCaseCompleted'], -- ]; -+ return []; - } - - public function onInitialTestSuiteStarted(InitialTestSuiteStarted $event): void diff --git a/src/CustomPatches/PHPInfectionNine.patch b/src/CustomPatches/PHPInfectionNine.patch deleted file mode 100644 index 5078bea..0000000 --- a/src/CustomPatches/PHPInfectionNine.patch +++ /dev/null @@ -1,20 +0,0 @@ ---- project/vendor/infection/infection/src/Performance/Listener/PerformanceLoggerSubscriber.php (date 1286705410000) -+++ project/vendor/infection/infection/src/Performance/Listener/PerformanceLoggerSubscriber.php (date 1286705410000) -@@ -69,15 +69,8 @@ - - public function onApplicationExecutionFinished(): void - { -- $time = $this->timer->stop(); -+ $this->timer->stop(); - -- $this->output->writeln([ -- '', -- sprintf( -- 'Time: %s. Memory: %s', -- $this->timeFormatter->toHumanReadableString($time), -- $this->memoryFormatter->toHumanReadableString(memory_get_peak_usage(true)) -- ), -- ]); -+ $this->output->writeln(''); - } - } diff --git a/src/CustomPatches/PHPInfectionOne.patch b/src/CustomPatches/PHPInfectionOne.patch deleted file mode 100644 index 329b142..0000000 --- a/src/CustomPatches/PHPInfectionOne.patch +++ /dev/null @@ -1,19 +0,0 @@ ---- project/vendor/infection/infection/src/Console/Application.php (date 1286705410000) -+++ project/vendor/infection/infection/src/Console/Application.php (date 1286705410000) -@@ -75,8 +75,6 @@ - $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); - } - -- $this->logRunningWithDebugger(); -- - if (!$this->isAutoExitEnabled()) { - // When we're not in control of exit codes, that means it's the caller - // responsibility to disable xdebug if it isn't needed. As of writing -@@ -113,8 +111,6 @@ - { - $this->getContainer()->buildDynamicDependencies($input); - -- $output->writeln(self::LOGO); -- - return parent::doRun($input, $output); - } diff --git a/src/CustomPatches/PHPInfectionSeven.patch b/src/CustomPatches/PHPInfectionSeven.patch deleted file mode 100644 index 5158644..0000000 --- a/src/CustomPatches/PHPInfectionSeven.patch +++ /dev/null @@ -1,19 +0,0 @@ ---- project/vendor/infection/infection/src/Process/Listener/MutationTestingConsoleLoggerSubscriber.php (date 1286705410000) -+++ project/vendor/infection/infection/src/Process/Listener/MutationTestingConsoleLoggerSubscriber.php (date 1286705410000) -@@ -102,16 +102,6 @@ - public function onMutationTestingFinished(MutationTestingFinished $event): void - { - $this->outputFormatter->finish(); -- -- if ($this->showMutations) { -- $this->showMutations($this->metricsCalculator->getEscapedMutantProcesses(), 'Escaped'); -- -- if ($this->output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) { -- $this->showMutations($this->metricsCalculator->getNotCoveredMutantProcesses(), 'Not covered'); -- } -- } -- -- $this->showMetrics(); - } - - /** diff --git a/src/CustomPatches/PHPInfectionSix.patch b/src/CustomPatches/PHPInfectionSix.patch deleted file mode 100644 index b11dd7b..0000000 --- a/src/CustomPatches/PHPInfectionSix.patch +++ /dev/null @@ -1,58 +0,0 @@ ---- project/vendor/infection/infection/src/Process/Listener/MutationGeneratingConsoleLoggerSubscriber.php (date 1286705410000) -+++ project/vendor/infection/infection/src/Process/Listener/MutationGeneratingConsoleLoggerSubscriber.php (date 1286705410000) -@@ -40,6 +40,7 @@ - use Infection\Events\MutationGeneratingFinished; - use Infection\Events\MutationGeneratingStarted; - use Symfony\Component\Console\Helper\ProgressBar; -+use Symfony\Component\Console\Output\NullOutput; - use Symfony\Component\Console\Output\OutputInterface; - - /** -@@ -57,11 +58,16 @@ - */ - private $progressBar; - -+ /** -+ * @var int -+ */ -+ private $counter = 1; -+ - public function __construct(OutputInterface $output) - { - $this->output = $output; - -- $this->progressBar = new ProgressBar($this->output); -+ $this->progressBar = new ProgressBar(new NullOutput()); - $this->progressBar->setFormat('Processing source code files: %current%/%max%'); - } - -@@ -76,12 +82,29 @@ - - public function onMutationGeneratingStarted(MutationGeneratingStarted $event): void - { -- $this->output->writeln(['', '', 'Generate mutants...', '']); - $this->progressBar->start($event->getMutableFilesCount()); - } - - public function onMutableFileProcessed(MutableFileProcessed $event): void - { -+ $numberLength = max(3, strlen((string) $this->progressBar->getMaxSteps())); -+ $maximumWidth = 50; -+ -+ $message = sprintf( -+ sprintf(' %%%sd / %%%sd (%%3d%%%%)', $numberLength, $numberLength), -+ $this->counter, -+ $this->progressBar->getMaxSteps(), -+ round(($this->counter / $this->progressBar->getMaxSteps()) * 100) -+ ); -+ -+ echo '.'; -+ echo $this->counter % $maximumWidth === 0 ? sprintf('%s%s', $message, PHP_EOL) : ''; -+ -+ if ($this->progressBar->getMaxSteps() == $this->counter) { -+ echo sprintf('%s%s%s', str_repeat(' ', $maximumWidth - $this->counter % $maximumWidth), $message, PHP_EOL); -+ } -+ -+ $this->counter++; - $this->progressBar->advance(); - } diff --git a/src/CustomPatches/PHPInfectionTen.patch b/src/CustomPatches/PHPInfectionTen.patch deleted file mode 100644 index c64ee52..0000000 --- a/src/CustomPatches/PHPInfectionTen.patch +++ /dev/null @@ -1,12 +0,0 @@ ---- project/vendor/infection/infection/src/Process/Builder/SubscriberBuilder.php (date 1286705410000) -+++ project/vendor/infection/infection/src/Process/Builder/SubscriberBuilder.php (date 1286705410000) -@@ -233,8 +233,6 @@ - - private function shouldSkipProgressBars(): bool - { -- return $this->input->getOption('no-progress') -- || getenv('CI') === 'true' -- || getenv('CONTINUOUS_INTEGRATION') === 'true'; -+ return $this->input->getOption('no-progress'); - } - } diff --git a/src/CustomPatches/PHPInfectionThree.patch b/src/CustomPatches/PHPInfectionThree.patch deleted file mode 100644 index a55da1f..0000000 --- a/src/CustomPatches/PHPInfectionThree.patch +++ /dev/null @@ -1,13 +0,0 @@ ---- project/vendor/infection/infection/src/Process/Listener/CleanUpAfterMutationTestingFinishedSubscriber.php (date 1286705410000) -+++ project/vendor/infection/infection/src/Process/Listener/CleanUpAfterMutationTestingFinishedSubscriber.php (date 1286705410000) -@@ -36,9 +36,7 @@ - - public function getSubscribedEvents(): array - { -- return [ -- MutationTestingFinished::class => [$this, 'onMutationTestingFinished'], -- ]; -+ return []; - } - - public function onMutationTestingFinished(MutationTestingFinished $event): void diff --git a/src/CustomPatches/PHPInfectionTwo.patch b/src/CustomPatches/PHPInfectionTwo.patch deleted file mode 100644 index c515abf..0000000 --- a/src/CustomPatches/PHPInfectionTwo.patch +++ /dev/null @@ -1,53 +0,0 @@ ---- project/vendor/infection/infection/src/Console/OutputFormatter/DotFormatter.php (date 1286705410000) -+++ project/vendor/infection/infection/src/Console/OutputFormatter/DotFormatter.php (date 1286705410000) -@@ -56,25 +56,14 @@ - $this->output = $output; - } - -- public function start(int $mutationCount): void -- { -- parent::start($mutationCount); -- -- $this->output->writeln([ -- '', -- '.: killed, ' -- . 'M: escaped, ' -- . 'S: uncovered, ' -- . 'E: fatal error, ' -- . 'T: timed out', -- '', -- ]); -- } -- - public function advance(MutantProcessInterface $mutantProcess, int $mutationCount): void - { - parent::advance($mutantProcess, $mutationCount); - -+ if ($this->callsCount === 1) { -+ $this->output->writeln(''); -+ } -+ - switch ($mutantProcess->getResultCode()) { - case MutantProcess::CODE_KILLED: - $this->output->write('.'); -@@ -85,7 +74,7 @@ - - break; - case MutantProcess::CODE_ESCAPED: -- $this->output->write('M'); -+ $this->output->write('F'); - - break; - case MutantProcess::CODE_TIMED_OUT: -@@ -108,9 +97,9 @@ - - if ($lastDot || $endOfRow) { - $length = \strlen((string) $mutationCount); -- $format = sprintf(' (%%%dd / %%%dd)', $length, $length); -+ $format = sprintf(' %%%dd / %%%dd (%%3d%%%%)', max(3, $length), max(3, $length)); - -- $this->output->write(sprintf($format, $this->callsCount, $mutationCount)); -+ $this->output->write(sprintf($format, $this->callsCount, $mutationCount, ($this->callsCount / $mutationCount) * 100)); - - if ($this->callsCount !== $mutationCount) { - $this->output->writeln(''); diff --git a/src/CustomPatches/PHPParaTest.patch b/src/CustomPatches/PHPParaTest.patch deleted file mode 100644 index b9a6f91..0000000 --- a/src/CustomPatches/PHPParaTest.patch +++ /dev/null @@ -1,63 +0,0 @@ ---- project/vendor/brianium/paratest/src/Runners/PHPUnit/ResultPrinter.php (date 1286705410000) -+++ project/vendor/brianium/paratest/src/Runners/PHPUnit/ResultPrinter.php (date 1286705410000) -@@ -135,19 +135,7 @@ - public function start(Options $options) - { - $this->numTestsWidth = \strlen((string) $this->totalCases); -- $this->maxColumn = $this->numberOfColumns -- + (\DIRECTORY_SEPARATOR === '\\' ? -1 : 0) // fix windows blank lines -- - \strlen($this->getProgress()); -- printf( -- "\nRunning phpunit in %d process%s with %s%s\n\n", -- $options->processes, -- $options->processes > 1 ? 'es' : '', -- $options->phpunit, -- $options->functional ? '. Functional mode is ON.' : '' -- ); -- if (isset($options->filtered['configuration'])) { -- printf("Configuration read from %s\n\n", $options->filtered['configuration']->getPath()); -- } -+ $this->maxColumn = 50; - $this->timer->start(); - $this->colors = $options->colors; - $this->processSkipped = $this->isSkippedIncompleTestCanBeTracked($options); -@@ -177,11 +165,10 @@ - */ - public function printResults() - { -- echo $this->getHeader(); - echo $this->getErrors(); - echo $this->getFailures(); - echo $this->getWarnings(); -- echo $this->getFooter(); -+ echo PHP_EOL; - } - - /** -@@ -411,6 +398,11 @@ - echo $this->getProgress(); - $this->println(); - } -+ -+ if ($this->casesProcessed === $this->totalCases) { -+ echo str_repeat(' ', $this->maxColumn - $this->column); -+ echo $this->getProgress(); -+ } - } - - /** -@@ -428,13 +420,7 @@ - if ($count === 0) { - return ''; - } -- $output = sprintf( -- "There %s %d %s%s:\n", -- ($count === 1) ? 'was' : 'were', -- $count, -- $type, -- ($count === 1) ? '' : 's' -- ); -+ $output = PHP_EOL; - - for ($i = 1; $i <= \count($defects); ++$i) { - $output .= sprintf("\n%d) %s\n", $i, $defects[$i - 1]); diff --git a/src/CustomPatches/PHPStanOne.patch b/src/CustomPatches/PHPStanOne.patch deleted file mode 100644 index d04b004..0000000 --- a/src/CustomPatches/PHPStanOne.patch +++ /dev/null @@ -1,71 +0,0 @@ ---- project/vendor/phpstan/phpstan/src/Command/ErrorsConsoleStyle.php (date 1286705410000) -+++ project/vendor/phpstan/phpstan/src/Command/ErrorsConsoleStyle.php (date 1286705410000) -@@ -17,6 +17,9 @@ - /** @var \Symfony\Component\Console\Helper\ProgressBar */ - private $progressBar; - -+ /** @var int */ -+ private $counter = 1; -+ - public function __construct(InputInterface $input, OutputInterface $output) - { - parent::__construct($input, $output); -@@ -81,7 +84,8 @@ - if (!$this->showProgress) { - return; - } -- parent::progressStart($max); -+ -+ $this->createProgressBar($max); - } - - /** -@@ -90,19 +94,28 @@ - */ - public function progressAdvance($step = 1): void - { -- if (!$this->showProgress) { -- return; -- } -- if ($step > 0) { -- $stepTime = (time() - $this->progressBar->getStartTime()) / $step; -- if ($stepTime > 0 && $stepTime < 1) { -- $this->progressBar->setRedrawFrequency((int) (1 / $stepTime)); -- } else { -- $this->progressBar->setRedrawFrequency(1); -- } -- } -+ if (!$this->showProgress) { -+ return; -+ } -+ -+ $numberLength = strlen((string) $this->progressBar->getMaxSteps()); -+ $maximumWidth = 50; -+ -+ $message = sprintf( -+ sprintf(' %%%sd / %%%sd (%%3d%%%%)', $numberLength, $numberLength), -+ $this->counter, -+ $this->progressBar->getMaxSteps(), -+ round(($this->counter / $this->progressBar->getMaxSteps()) * 100) -+ ); -+ -+ $this->write('.'); -+ $this->write($this->counter % $maximumWidth === 0 ? sprintf('%s%s', $message, PHP_EOL) : ''); -+ -+ if ($this->progressBar->getMaxSteps() == $this->counter) { -+ $this->write(sprintf('%s%s%s', str_repeat(' ', $maximumWidth - $this->counter % $maximumWidth), $message, PHP_EOL)); -+ } - -- $this->progressBar->setProgress($this->progressBar->getProgress() + $step); -+ $this->counter++; - } - - public function progressFinish(): void -@@ -110,7 +123,6 @@ - if (!$this->showProgress) { - return; - } -- parent::progressFinish(); - } - - } diff --git a/src/CustomPatches/PHPStanTwo.patch b/src/CustomPatches/PHPStanTwo.patch deleted file mode 100644 index d9ba6a5..0000000 --- a/src/CustomPatches/PHPStanTwo.patch +++ /dev/null @@ -1,41 +0,0 @@ ---- project/vendor/phpstan/phpstan/src/Command/ErrorFormatter/TableErrorFormatter.php (date 1286705410000) -+++ project/vendor/phpstan/phpstan/src/Command/ErrorFormatter/TableErrorFormatter.php (date 1286705410000) -@@ -41,34 +41,10 @@ - ): int - { - if (!$analysisResult->hasErrors()) { -- $style->success('No errors'); -- if ($this->showTipsOfTheDay) { -- if ($analysisResult->isDefaultLevelUsed()) { -- $style->writeln('💡 Tip of the Day:'); -- $style->writeln(sprintf( -- "PHPStan is performing only the most basic checks.\nYou can pass a higher rule level through the --%s option\n(the default and current level is %d) to analyse code more thoroughly.", -- AnalyseCommand::OPTION_LEVEL, -- AnalyseCommand::DEFAULT_LEVEL -- )); -- $style->writeln(''); -- } elseif ( -- !$this->checkThisOnly -- && $analysisResult->hasInferrablePropertyTypesFromConstructor() -- && !$this->inferPrivatePropertyTypeFromConstructor -- ) { -- $projectConfigFile = 'phpstan.neon'; -- if ($analysisResult->getProjectConfigFile() !== null) { -- $projectConfigFile = $this->relativePathHelper->getRelativePath($analysisResult->getProjectConfigFile()); -- } -- $style->writeln('💡 Tip of the Day:'); -- $style->writeln("One or more properties in your code do not have a phpDoc with a type\nbut it could be inferred from the constructor to find more bugs."); -- $style->writeln(sprintf('Use inferPrivatePropertyTypeFromConstructor: true in your %s to try it out!', $projectConfigFile)); -- $style->writeln(''); -- } -- } -- -- return 0; -- } -+ return 0; -+ } -+ -+ $style->writeln(''); - - /** @var array $fileErrors */ - $fileErrors = []; diff --git a/src/CustomPatches/PHPUnitOne.patch b/src/CustomPatches/PHPUnitOne.patch deleted file mode 100644 index 4461345..0000000 --- a/src/CustomPatches/PHPUnitOne.patch +++ /dev/null @@ -1,145 +0,0 @@ ---- project/vendor/phpunit/phpunit/src/TextUI/TestRunner.php (date 1286705410000) -+++ project/vendor/phpunit/phpunit/src/TextUI/TestRunner.php (date 1286705410000) -@@ -302,10 +302,6 @@ - $this->printer->setShowProgressAnimation(!$arguments['noInteraction']); - } - -- $this->printer->write( -- Version::getVersionString() . "\n" -- ); -- - self::$versionStringPrinted = true; - - if ($arguments['verbose']) { -@@ -575,8 +571,6 @@ - exit(self::SUCCESS_EXIT); - } - -- $this->printer->write("\n"); -- - if (isset($codeCoverage)) { - $result->setCodeCoverage($codeCoverage); - -@@ -632,38 +626,24 @@ - - if (isset($codeCoverage)) { - if (isset($arguments['coverageClover'])) { -- $this->codeCoverageGenerationStart('Clover XML'); -- - try { - $writer = new CloverReport; - $writer->process($codeCoverage, $arguments['coverageClover']); -- -- $this->codeCoverageGenerationSucceeded(); -- - unset($writer); - } catch (CodeCoverageException $e) { -- $this->codeCoverageGenerationFailed($e); - } - } - - if (isset($arguments['coverageCrap4J'])) { -- $this->codeCoverageGenerationStart('Crap4J XML'); -- - try { - $writer = new Crap4jReport($arguments['crap4jThreshold']); - $writer->process($codeCoverage, $arguments['coverageCrap4J']); -- -- $this->codeCoverageGenerationSucceeded(); -- - unset($writer); - } catch (CodeCoverageException $e) { -- $this->codeCoverageGenerationFailed($e); - } - } - - if (isset($arguments['coverageHtml'])) { -- $this->codeCoverageGenerationStart('HTML'); -- - try { - $writer = new HtmlReport( - $arguments['reportLowUpperBound'], -@@ -675,27 +655,17 @@ - ); - - $writer->process($codeCoverage, $arguments['coverageHtml']); -- -- $this->codeCoverageGenerationSucceeded(); -- - unset($writer); - } catch (CodeCoverageException $e) { -- $this->codeCoverageGenerationFailed($e); - } - } - - if (isset($arguments['coveragePHP'])) { -- $this->codeCoverageGenerationStart('PHP'); -- - try { - $writer = new PhpReport; - $writer->process($codeCoverage, $arguments['coveragePHP']); -- -- $this->codeCoverageGenerationSucceeded(); -- - unset($writer); - } catch (CodeCoverageException $e) { -- $this->codeCoverageGenerationFailed($e); - } - } - -@@ -721,17 +691,11 @@ - } - - if (isset($arguments['coverageXml'])) { -- $this->codeCoverageGenerationStart('PHPUnit XML'); -- - try { - $writer = new XmlReport(Version::id()); - $writer->process($codeCoverage, $arguments['coverageXml']); -- -- $this->codeCoverageGenerationSucceeded(); -- - unset($writer); - } catch (CodeCoverageException $e) { -- $this->codeCoverageGenerationFailed($e); - } - } - } -@@ -1308,37 +1272,4 @@ - $arguments['reverseList'] - ); - } -- -- private function codeCoverageGenerationStart(string $format): void -- { -- $this->printer->write( -- \sprintf( -- "\nGenerating code coverage report in %s format ... ", -- $format -- ) -- ); -- -- Timer::start(); -- } -- -- private function codeCoverageGenerationSucceeded(): void -- { -- $this->printer->write( -- \sprintf( -- "done [%s]\n", -- Timer::secondsToTimeString(Timer::stop()) -- ) -- ); -- } -- -- private function codeCoverageGenerationFailed(\Exception $e): void -- { -- $this->printer->write( -- \sprintf( -- "failed [%s]\n%s\n", -- Timer::secondsToTimeString(Timer::stop()), -- $e->getMessage() -- ) -- ); -- } - } diff --git a/src/CustomPatches/PHPUnitTwo.patch b/src/CustomPatches/PHPUnitTwo.patch deleted file mode 100644 index 4f69f79..0000000 --- a/src/CustomPatches/PHPUnitTwo.patch +++ /dev/null @@ -1,118 +0,0 @@ ---- project/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php (date 1286705410000) -+++ project/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php (date 1286705410000) -@@ -236,7 +236,7 @@ - if ($this->numTests == -1) { - $this->numTests = \count($suite); - $this->numTestsWidth = \strlen((string) $this->numTests); -- $this->maxColumn = $this->numberOfColumns - \strlen(' / (XXX%)') - (2 * $this->numTestsWidth); -+ $this->maxColumn = 50; - } - } - -@@ -302,18 +302,10 @@ - } - - if ($this->defectListPrinted) { -- $this->write("\n--\n\n"); -+ $this->write("\033[1A"); - } - -- $this->write( -- \sprintf( -- "There %s %d %s%s:\n", -- ($count == 1) ? 'was' : 'were', -- $count, -- $type, -- ($count == 1) ? '' : 's' -- ) -- ); -+ $this->write(PHP_EOL); - - $i = 1; - -@@ -390,83 +382,12 @@ - */ - protected function printHeader(): void - { -- $this->write("\n\n" . Timer::resourceUsage() . "\n\n"); -+ - } - - protected function printFooter(TestResult $result): void - { -- if (\count($result) === 0) { -- $this->writeWithColor( -- 'fg-black, bg-yellow', -- 'No tests executed!' -- ); -- -- return; -- } -- -- if ($result->wasSuccessful() && -- $result->allHarmless() && -- $result->allCompletelyImplemented() && -- $result->noneSkipped()) { -- $this->writeWithColor( -- 'fg-black, bg-green', -- \sprintf( -- 'OK (%d test%s, %d assertion%s)', -- \count($result), -- (\count($result) == 1) ? '' : 's', -- $this->numAssertions, -- ($this->numAssertions == 1) ? '' : 's' -- ) -- ); -- } else { -- if ($result->wasSuccessful()) { -- $color = 'fg-black, bg-yellow'; -- -- if ($this->verbose || !$result->allHarmless()) { -- $this->write("\n"); -- } -- -- $this->writeWithColor( -- $color, -- 'OK, but incomplete, skipped, or risky tests!' -- ); -- } else { -- $this->write("\n"); -- -- if ($result->errorCount()) { -- $color = 'fg-white, bg-red'; -- -- $this->writeWithColor( -- $color, -- 'ERRORS!' -- ); -- } elseif ($result->failureCount()) { -- $color = 'fg-white, bg-red'; -- -- $this->writeWithColor( -- $color, -- 'FAILURES!' -- ); -- } elseif ($result->warningCount()) { -- $color = 'fg-black, bg-yellow'; -- -- $this->writeWithColor( -- $color, -- 'WARNINGS!' -- ); -- } -- } -- -- $this->writeCountString(\count($result), 'Tests', $color, true); -- $this->writeCountString($this->numAssertions, 'Assertions', $color, true); -- $this->writeCountString($result->errorCount(), 'Errors', $color); -- $this->writeCountString($result->failureCount(), 'Failures', $color); -- $this->writeCountString($result->warningCount(), 'Warnings', $color); -- $this->writeCountString($result->skippedCount(), 'Skipped', $color); -- $this->writeCountString($result->notImplementedCount(), 'Incomplete', $color); -- $this->writeCountString($result->riskyCount(), 'Risky', $color); -- $this->writeWithColor($color, '.'); -- } -+ $this->write(PHP_EOL); - } - - protected function writeProgress(string $progress): void diff --git a/src/CustomReports/PhpCodeSnifferReport.php b/src/CustomReports/PhpCodeSnifferReport.php new file mode 100644 index 0000000..0fbe301 --- /dev/null +++ b/src/CustomReports/PhpCodeSnifferReport.php @@ -0,0 +1,94 @@ +root = sprintf('%s/', getcwd()); + } + + /** + * @param mixed $report + * @param File $phpcsFile + * @param mixed $showSources + * @param mixed $width + * + * @return bool + */ + public function generateFileReport($report, File $phpcsFile, $showSources = FALSE, $width = 80): bool + { + $phpcsFile; + $showSources; + $width; + + if (count($report['messages']) > 0) { + $path = str_replace($this->root, '', $report['filename']); + + foreach ($report['messages'] as $rowNumber => $rows) { + foreach ($rows as $cols) { + foreach ($cols as $message) { + echo sprintf('%s:%s: %s%s', $path, $rowNumber, $message['message'], PHP_EOL); + } + } + } + } + + return TRUE; + } + + /** + * @param mixed $cachedData + * @param mixed $totalFiles + * @param mixed $totalErrors + * @param mixed $totalWarnings + * @param mixed $totalFixable + * @param mixed $showSources + * @param mixed $width + * @param mixed $interactive + * @param mixed $toScreen + */ + public function generate( + $cachedData, + $totalFiles, + $totalErrors, + $totalWarnings, + $totalFixable, + $showSources = FALSE, + $width = 80, + $interactive = FALSE, + $toScreen = TRUE + ): void { + $totalFiles; + $totalErrors; + $totalWarnings; + $totalFixable; + $showSources; + $width; + $interactive; + $toScreen; + + if (strlen($cachedData) !== 0) { + echo sprintf('%s%sErrors: %s%s%s', $cachedData, PHP_EOL, $totalErrors, PHP_EOL, PHP_EOL); + } + } + +} \ No newline at end of file diff --git a/src/CustomReports/PhpStanReport.php b/src/CustomReports/PhpStanReport.php new file mode 100644 index 0000000..2389beb --- /dev/null +++ b/src/CustomReports/PhpStanReport.php @@ -0,0 +1,76 @@ +root = sprintf('%s/', getcwd()); + } + + /** + * @param AnalysisResult $analysisResult + * @param Output $style + * + * @return int + */ + public function formatErrors(AnalysisResult $analysisResult, Output $style): int + { + $style = $style->getStyle(); + + /** @var Error[][] $fileErrors */ + $fileErrors = []; + + foreach ($analysisResult->getFileSpecificErrors() as $fileSpecificError) { + if (!isset($fileErrors[$fileSpecificError->getFile()])) { + $fileErrors[$fileSpecificError->getFile()] = []; + } + + $fileErrors[$fileSpecificError->getFile()][] = $fileSpecificError; + } + + foreach ($fileErrors as $file => $errors) { + foreach ($errors as $error) { + echo sprintf( + '%s:%s: %s', + str_replace($this->root, '', $file), + $error->getLine() ?? '?', + $error->getMessage() + ); + $style->newLine(); + } + } + + foreach ($analysisResult->getNotFileSpecificErrors() as $notFileSpecificError) { + echo $notFileSpecificError; + $style->newLine(); + } + + if ($analysisResult->getTotalErrorsCount() !== 0) { + echo sprintf('%sErrors: %s%s%s', PHP_EOL, $analysisResult->getTotalErrorsCount(), PHP_EOL, PHP_EOL); + } + + return $analysisResult->hasErrors() ? 1 : 0; + } + +} \ No newline at end of file diff --git a/src/CustomRules/Analyzer.php b/src/CustomRules/Analyzer.php index dff10cc..ed17f16 100644 --- a/src/CustomRules/Analyzer.php +++ b/src/CustomRules/Analyzer.php @@ -23,21 +23,18 @@ public static function phpCodeSniffer(string $data): int $results = []; $record = FALSE; $total = 0; - $logs = array_map( - static function (string $row): string { - return trim($row); - }, - explode(PHP_EOL, $data) - ); + $logs = array_map(static fn (string $row): string => trim($row), explode(PHP_EOL, $data)); foreach ($logs as $log) { if ($log === '*** START SNIFF PROCESSING REPORT ***') { $record = TRUE; + continue; } if ($log === '*** END SNIFF PROCESSING REPORT ***') { $record = FALSE; + continue; } @@ -61,19 +58,14 @@ static function (string $row): string { } } - usort( - $results, - static function (array $one, array $two): int { - return $two[1] <=> $one[1]; - } - ); + usort($results, static fn (array $one, array $two): int => $two[1] <=> $one[1]); echo sprintf( '%07.3fs (100.000%%): Analyzed %s rows of logs in %07.3fs with %07.3fMB RAM usage%s', $total, number_format(count($logs), 0, '.', ' '), microtime(TRUE) - $timestamp, - memory_get_peak_usage(TRUE) / 1024 ** 2, + memory_get_peak_usage(TRUE) / 1_024 ** 2, PHP_EOL ); @@ -99,10 +91,12 @@ public static function phpUnit(string $data): int $timestamp = microtime(TRUE); $results = []; $total = 0; - $logs = (new SimpleXMLElement($data))->xpath('//testcase') ?: []; + $logs = (new SimpleXMLElement($data))->xpath('//testcase'); + $logs = is_array($logs) ? $logs : []; /** @var SimpleXMLElement $log */ foreach ($logs as $log) { + /** @var SimpleXMLElement $attributes */ $attributes = $log->attributes(); $time = (float) $attributes['time']; $total += $time; @@ -113,19 +107,14 @@ public static function phpUnit(string $data): int ]; } - usort( - $results, - static function (array $one, array $two): int { - return $two[1] <=> $one[1]; - } - ); + usort($results, static fn (array $one, array $two): int => $two[1] <=> $one[1]); echo sprintf( '%07.3fs (100.000%%): Analyzed %s rows of logs in %07.3fs with %07.3fMB RAM usage%s', $total, number_format(count($logs), 0, '.', ' '), microtime(TRUE) - $timestamp, - memory_get_peak_usage(TRUE) / 1024 ** 2, + memory_get_peak_usage(TRUE) / 1_024 ** 2, PHP_EOL ); @@ -141,4 +130,33 @@ static function (array $one, array $two): int { return 0; } + /** + * @param int $minimum + * @param string $path + * + * @return int + */ + public static function phpUnitCoverage(int $minimum, string $path): int + { + /** @var SimpleXMLElement $coverage */ + $coverage = simplexml_load_file($path); + $coverage->registerXPathNamespace('php', 'https://schema.phpunit.de/coverage/1.0'); + $coverage = $coverage->xpath('//php:project/php:directory/php:totals/php:lines'); + $coverage = is_array($coverage) ? (float) $coverage[0]['percent'] : 0; + + if ($coverage >= $minimum) { + return 0; + } + + echo sprintf( + '%sMinimum required code coverage is %s%%, but actual is %s%%!%s', + PHP_EOL, + $minimum, + $coverage, + PHP_EOL + ); + + return 1; + } + } \ No newline at end of file diff --git a/src/CustomRules/Sniffs/Commenting/AbstractSniff.php b/src/CustomRules/Sniffs/Commenting/AbstractSniff.php index 26bab7b..57af315 100644 --- a/src/CustomRules/Sniffs/Commenting/AbstractSniff.php +++ b/src/CustomRules/Sniffs/Commenting/AbstractSniff.php @@ -29,9 +29,9 @@ abstract class AbstractSniff implements Sniff ]; /** - * @var array + * @var mixed[] */ - public $comments = [ + public array $comments = [ '{TYPE} {NAME}', '@package {NAMESPACE}', ]; @@ -71,7 +71,7 @@ protected function getNamespaceName(File $file, int $position): string * @param File $file * @param int $position * - * @return array + * @return mixed[] */ protected function getDocumentComment(File $file, int $position): array { @@ -99,23 +99,18 @@ protected function getDocumentComment(File $file, int $position): array } } - return array_filter( - array_map('trim', $result), - static function (string $item): bool { - return strlen($item) > 0; - } - ); + return array_filter(array_map('trim', $result), static fn (string $item): bool => strlen($item) > 0); } /** * @param File $file * @param int $position * @param string $type - * @param string|NULL $customName + * @param string|null $customName * - * @return int|void + * @return int */ - protected function processCommenting(File $file, int $position, string $type, ?string $customName = NULL) + protected function processCommenting(File $file, int $position, string $type, ?string $customName = NULL): int { $position = $file->findNext(T_STRING, $position); @@ -134,6 +129,8 @@ protected function processCommenting(File $file, int $position, string $type, ?s } } } + + return 0; } /** @@ -141,7 +138,7 @@ protected function processCommenting(File $file, int $position, string $type, ?s * @param int $position * @param string $type * @param string $string - * @param string|NULL $customName + * @param string|null $customName * * @return string */ @@ -156,7 +153,7 @@ protected function replacePlaceholders( self::REPLACE, [ $this->getNamespaceName($file, $position), - $customName ?: $file->getTokens()[$position][self::CONTENT], + is_string($customName) ? $customName : $file->getTokens()[$position][self::CONTENT], $type, ], $string diff --git a/src/CustomRules/Sniffs/Commenting/ClassSniff.php b/src/CustomRules/Sniffs/Commenting/ClassSniff.php index 642ed5f..3cd5aa7 100644 --- a/src/CustomRules/Sniffs/Commenting/ClassSniff.php +++ b/src/CustomRules/Sniffs/Commenting/ClassSniff.php @@ -24,11 +24,13 @@ public function register(): array * @param File $file * @param mixed $position * - * @return int|void + * @return int */ - public function process(File $file, $position) + public function process(File $file, $position): int { $this->processCommenting($file, $position, self::TYPE_CLASS); + + return 0; } } \ No newline at end of file diff --git a/src/CustomRules/Sniffs/Commenting/ConstructorSniff.php b/src/CustomRules/Sniffs/Commenting/ConstructorSniff.php index fe2eb94..a598faa 100644 --- a/src/CustomRules/Sniffs/Commenting/ConstructorSniff.php +++ b/src/CustomRules/Sniffs/Commenting/ConstructorSniff.php @@ -13,14 +13,14 @@ final class ConstructorSniff extends AbstractSniff { /** - * @var array + * @var mixed[] */ - public $comments = ['{NAME} constructor']; + public array $comments = ['{NAME} constructor']; /** * @var string */ - public $anonymousName = 'Anonymous'; + public string $anonymousName = 'Anonymous'; /** * @return int[] @@ -34,9 +34,9 @@ public function register(): array * @param File $file * @param mixed $position * - * @return int|void + * @return int */ - public function process(File $file, $position) + public function process(File $file, $position): int { $tokens = $file->getTokens(); @@ -62,6 +62,8 @@ public function process(File $file, $position) } } } + + return 0; } } \ No newline at end of file diff --git a/src/CustomRules/Sniffs/Commenting/FunctionSniff.php b/src/CustomRules/Sniffs/Commenting/FunctionSniff.php index 4d67505..6d86615 100644 --- a/src/CustomRules/Sniffs/Commenting/FunctionSniff.php +++ b/src/CustomRules/Sniffs/Commenting/FunctionSniff.php @@ -13,9 +13,9 @@ final class FunctionSniff extends AbstractSniff { /** - * @var array + * @var mixed[] */ - public $rules = ['#(\|null|null\||NULL\|)#' => 'Usage of non-rightmost NULL type hint is not allowed.']; + public array $rules = ['#(?:\|NULL|null\||NULL\|)#' => 'Usage of non-rightmost null type hint is not allowed.']; /** * @return int[] @@ -29,15 +29,17 @@ public function register(): array * @param File $file * @param mixed $position * - * @return int|void + * @return int */ - public function process(File $file, $position) + public function process(File $file, $position): int { foreach ($this->rules as $pattern => $message) { if (preg_match($pattern, $file->getTokens()[$position][self::CONTENT]) === 1) { $file->addError($message, $position, 'Comment'); } } + + return 0; } } \ No newline at end of file diff --git a/src/CustomRules/Sniffs/Commenting/InterfaceSniff.php b/src/CustomRules/Sniffs/Commenting/InterfaceSniff.php index 5027026..4ddd1bf 100644 --- a/src/CustomRules/Sniffs/Commenting/InterfaceSniff.php +++ b/src/CustomRules/Sniffs/Commenting/InterfaceSniff.php @@ -24,11 +24,13 @@ public function register(): array * @param File $file * @param mixed $position * - * @return int|void + * @return int */ - public function process(File $file, $position) + public function process(File $file, $position): int { $this->processCommenting($file, $position, self::TYPE_INTERFACE); + + return 0; } } \ No newline at end of file diff --git a/src/CustomRules/Sniffs/Commenting/TraitSniff.php b/src/CustomRules/Sniffs/Commenting/TraitSniff.php index c157ac3..9fd401b 100644 --- a/src/CustomRules/Sniffs/Commenting/TraitSniff.php +++ b/src/CustomRules/Sniffs/Commenting/TraitSniff.php @@ -24,11 +24,13 @@ public function register(): array * @param File $file * @param mixed $position * - * @return int|void + * @return int */ - public function process(File $file, $position) + public function process(File $file, $position): int { $this->processCommenting($file, $position, self::TYPE_TRAIT); + + return 0; } } \ No newline at end of file diff --git a/src/CustomRules/Sniffs/Functions/ParentSniff.php b/src/CustomRules/Sniffs/Functions/ParentSniff.php deleted file mode 100644 index 830c5ab..0000000 --- a/src/CustomRules/Sniffs/Functions/ParentSniff.php +++ /dev/null @@ -1,50 +0,0 @@ -findNext(T_SEMICOLON, $position); - $closePosition = $file->findNext(T_SEMICOLON, $startPosition + 1); - - if (is_int($closePosition) && $closePosition === $file->findEndOfStatement($startPosition)) { - for ($iterator = 1; $iterator < 3; $iterator++) { - $token = $file->getTokens()[$startPosition + $iterator]; - - if ($token[self::CODE] !== T_WHITESPACE || preg_match(self::PATTERN, $token[self::CONTENT]) === 0) { - $file->addError('Usage of parent call without single blank line is not allowed.', $position, 'NewLine'); - } - } - } - } - -} \ No newline at end of file diff --git a/src/CustomRules/Sniffs/Functions/TestSniff.php b/src/CustomRules/Sniffs/Functions/TestSniff.php index 32ed167..4961340 100644 --- a/src/CustomRules/Sniffs/Functions/TestSniff.php +++ b/src/CustomRules/Sniffs/Functions/TestSniff.php @@ -25,14 +25,13 @@ public function register(): array * @param File $file * @param mixed $position * - * @return int|void + * @return int */ - public function process(File $file, $position) + public function process(File $file, $position): int { - $tokens = $file->getTokens(); - $coverages = []; - $annotations = []; - $startPosition = (int) $position; + $tokens = $file->getTokens(); + $coverages = []; + $annotations = []; if (substr($tokens[$position + 2][self::CONTENT], -4) === 'Test') { $position = $file->findNext(T_FUNCTION, $position + 1); @@ -50,9 +49,11 @@ public function process(File $file, $position) foreach ($this->getDocumentComment($file, $innerPosition) as $comment) { if (strpos($comment, '@covers') !== FALSE) { - $hasCoverage = TRUE; + $hasCoverage = TRUE; + $hasNotNamespace = strpos($comment, '\\') === FALSE; + $hasNotCoversNothing = strpos($comment, '@coversNothing') === FALSE; - if (strpos($comment, '\\') !== FALSE) { + if ($hasNotNamespace && $hasNotCoversNothing) { $annotations[] = $innerPosition; } } @@ -69,10 +70,6 @@ public function process(File $file, $position) } if ($hasTests) { - if (!is_int($file->findPrevious(T_FINAL, $startPosition))) { - $file->addError('Usage of abstract or normal test class is not allowed.', $startPosition, 'Final'); - } - foreach ($coverages as $coverage) { $file->addError( 'Usage of test method without @covers annotation is not allowed.', @@ -83,13 +80,15 @@ public function process(File $file, $position) foreach ($annotations as $annotation) { $file->addError( - 'Usage of @covers annotation with namespace is not allowed.', + 'Usage of @covers annotation without namespace is not allowed.', $annotation, 'Covers' ); } } } + + return 0; } } \ No newline at end of file diff --git a/src/CustomRules/Sniffs/Strings/ConcatenationSniff.php b/src/CustomRules/Sniffs/Strings/ConcatenationSniff.php index a93cfe3..a52e9ca 100644 --- a/src/CustomRules/Sniffs/Strings/ConcatenationSniff.php +++ b/src/CustomRules/Sniffs/Strings/ConcatenationSniff.php @@ -17,16 +17,16 @@ final class ConcatenationSniff implements Sniff private const __DIR__ = '__DIR__'; /** - * @var array + * @var mixed[] */ - public $start = [ + public array $start = [ self::__DIR__, ]; /** - * @var array + * @var mixed[] */ - public $close = [ + public array $close = [ self::__DIR__, ]; @@ -42,9 +42,9 @@ public function register(): array * @param File $file * @param mixed $position * - * @return int|void + * @return int */ - public function process(File $file, $position) + public function process(File $file, $position): int { $start = $file->getTokens()[$position + 2][self::CONTENT]; $close = $file->getTokens()[$position - 2][self::CONTENT]; @@ -52,6 +52,8 @@ public function process(File $file, $position) if (!in_array($close, $this->start, TRUE) && !in_array($start, $this->close, TRUE)) { $file->addError('Usage of string concatenation operator is not allowed.', $position, 'Concatenation'); } + + return 0; } } \ No newline at end of file diff --git a/src/phpunit.xml b/src/phpunit.xml new file mode 100644 index 0000000..ac3b691 --- /dev/null +++ b/src/phpunit.xml @@ -0,0 +1,20 @@ + + + + tests + + + + + src + + + + + + + + + + + \ No newline at end of file diff --git a/src/ruleset.neon b/src/ruleset.neon index e1c0543..2e482f2 100644 --- a/src/ruleset.neon +++ b/src/ruleset.neon @@ -6,4 +6,8 @@ includes: - ./../../../phpstan/phpstan-phpunit/rules.neon - ./../../../phpstan/phpstan-doctrine/rules.neon - ./../../../phpstan/phpstan-strict-rules/rules.neon - - ./../../../phpstan/phpstan-deprecation-rules/rules.neon \ No newline at end of file + - ./../../../phpstan/phpstan-deprecation-rules/rules.neon + +services: + errorFormatter.custom: + factory: Bruha\CodingStandard\CustomReports\PhpStanReport \ No newline at end of file diff --git a/src/ruleset.xml b/src/ruleset.xml index 80f1b8d..ada5d0b 100644 --- a/src/ruleset.xml +++ b/src/ruleset.xml @@ -1,5 +1,9 @@ + + + + @@ -10,6 +14,7 @@ + @@ -82,23 +87,33 @@ + + + + - + + + + + + + @@ -110,7 +125,7 @@ - + @@ -150,24 +165,6 @@ - - - - - - - - - - - - - - - - - - @@ -186,4 +183,22 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index 50f7e6c..605be84 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -3,6 +3,7 @@ namespace Tests; use PHP_CodeSniffer\Config; +use PHP_CodeSniffer\Exceptions\DeepExitException; use PHP_CodeSniffer\Files\LocalFile; use PHP_CodeSniffer\Runner; use PHPUnit\Framework\TestCase; @@ -20,14 +21,16 @@ abstract class AbstractTestCase extends TestCase /** * @var Runner */ - private $runner; + private Runner $runner; /** * AbstractTestCase constructor * - * @param string|NULL $name - * @param array $data + * @param string|null $name + * @param mixed[] $data * @param string $dataName + * + * @throws DeepExitException */ public function __construct(?string $name = NULL, array $data = [], string $dataName = '') { @@ -99,6 +102,7 @@ protected function assertSuccess(LocalFile $file): void * @param string $class * @param string $name * @param string $message + * @param int $columnTwo */ protected function assertNotSuccess( LocalFile $file, @@ -107,9 +111,10 @@ protected function assertNotSuccess( int $rank, string $class, string $name, - string $message + string $message, + int $columnTwo = 0 ): void { - $error = $file->getErrors()[$row][$column][$rank]; + $error = $file->getErrors()[$row][$column][$rank] ?? $file->getErrors()[$row][$columnTwo][$rank]; self::assertEquals($class, $error['listener']); self::assertEquals($name, $error['source']); diff --git a/tests/Integration/CustomHooks/PhpUnitHookTest.php b/tests/Integration/CustomHooks/PhpUnitHookTest.php index 23b9f85..5139161 100644 --- a/tests/Integration/CustomHooks/PhpUnitHookTest.php +++ b/tests/Integration/CustomHooks/PhpUnitHookTest.php @@ -3,7 +3,6 @@ namespace Tests\Integration\CustomHooks; use Bruha\CodingStandard\CustomHooks\PhpUnitHook; -use DG\BypassFinals; use Tests\AbstractTestCase; use Tests\PrivateTrait; @@ -11,6 +10,8 @@ * Class PhpUnitHookTest * * @package Tests\Integration\CustomHooks + * + * @covers \Bruha\CodingStandard\CustomHooks\PhpUnitHook */ final class PhpUnitHookTest extends AbstractTestCase { @@ -20,30 +21,20 @@ final class PhpUnitHookTest extends AbstractTestCase /** * @var PhpUnitHook */ - private $hook; - - /** - * - */ - protected function setUp(): void - { - parent::setUp(); - - $this->hook = new PhpUnitHook(); - } + private PhpUnitHook $hook; /** - * @covers PhpUnitHook::executeBeforeTest + * @covers \Bruha\CodingStandard\CustomHooks\PhpUnitHook::executeBeforeTest */ public function testExecuteBeforeTest(): void { $this->hook->executeBeforeTest('Test'); - self::assertTrue(in_array(BypassFinals::PROTOCOL, stream_get_wrappers(), TRUE)); + self::assertTrue(in_array('file', stream_get_wrappers(), TRUE)); } /** - * @covers PhpUnitHook::executeAfterTest + * @covers \Bruha\CodingStandard\CustomHooks\PhpUnitHook::executeAfterTest */ public function testExecuteAfterTest(): void { @@ -55,7 +46,7 @@ public function testExecuteAfterTest(): void } /** - * @covers PhpUnitHook::executeAfterLastTest + * @covers \Bruha\CodingStandard\CustomHooks\PhpUnitHook::executeAfterLastTest */ public function testExecuteAfterLastTest(): void { @@ -69,14 +60,24 @@ public function testExecuteAfterLastTest(): void self::assertEquals('', array_pop($output)); self::assertEquals('', array_shift($output)); self::assertEquals('', array_shift($output)); - self::assertRegExp( + self::assertMatchesRegularExpression( '/\d+\.\d+s \(100\.000%\): Time analysis of \d+ tests:/', (string) array_shift($output) ); - self::assertRegExp( + self::assertMatchesRegularExpression( '/\d+\.\d+s \(\d+\.\d+%\): \w+::\w+/', (string) array_shift($output) ); } + /** + * + */ + protected function setUp(): void + { + parent::setUp(); + + $this->hook = new PhpUnitHook(); + } + } \ No newline at end of file diff --git a/tests/Integration/CustomPatches/PatchesTest.php b/tests/Integration/CustomPatches/PatchesTest.php deleted file mode 100644 index 9de8e54..0000000 --- a/tests/Integration/CustomPatches/PatchesTest.php +++ /dev/null @@ -1,112 +0,0 @@ -processPatch('squizlabs/php_codesniffer/src/Runner.php', 'PHPCodeSnifferOne.patch'); - $this->processPatch('squizlabs/php_codesniffer/src/Reports/Full.php', 'PHPCodeSnifferTwo.patch'); - } - - /** - * @coversNothing - */ - public function testPhpStan(): void - { - $this->processPatch('phpstan/phpstan/src/Command/ErrorsConsoleStyle.php', 'PHPStanOne.patch'); - $this->processPatch('phpstan/phpstan/src/Command/ErrorFormatter/TableErrorFormatter.php', 'PHPStanTwo.patch'); - } - - /** - * @coversNothing - */ - public function testPhpUnit(): void - { - $this->processPatch('phpunit/phpunit/src/TextUI/TestRunner.php', 'PHPUnitOne.patch'); - $this->processPatch('phpunit/phpunit/src/TextUI/ResultPrinter.php', 'PHPUnitTwo.patch'); - } - - /** - * @coversNothing - */ - public function testPhpParaTest(): void - { - $this->processPatch('brianium/paratest/src/Runners/PHPUnit/ResultPrinter.php', 'PHPParaTest.patch'); - } - - /** - * @coversNothing - */ - public function testPhpInfection(): void - { - $this->processPatch( - 'infection/infection/src/Console/Application.php', - 'PHPInfectionOne.patch' - ); - $this->processPatch( - 'infection/infection/src/Console/OutputFormatter/DotFormatter.php', - 'PHPInfectionTwo.patch' - ); - $this->processPatch( - 'infection/infection/src/Process/Listener/CleanUpAfterMutationTestingFinishedSubscriber.php', - 'PHPInfectionThree.patch' - ); - $this->processPatch( - 'infection/infection/src/Process/Listener/InitialTestsConsoleLoggerSubscriber.php', - 'PHPInfectionFour.patch' - ); - $this->processPatch( - 'infection/infection/src/Process/Listener/MutantCreatingConsoleLoggerSubscriber.php', - 'PHPInfectionFive.patch' - ); - $this->processPatch( - 'infection/infection/src/Process/Listener/MutationGeneratingConsoleLoggerSubscriber.php', - 'PHPInfectionSix.patch' - ); - $this->processPatch( - 'infection/infection/src/Process/Listener/MutationTestingConsoleLoggerSubscriber.php', - 'PHPInfectionSeven.patch' - ); - $this->processPatch( - 'infection/infection/src/Process/Listener/MutationTestingResultsLoggerSubscriber.php', - 'PHPInfectionEight.patch' - ); - $this->processPatch( - 'infection/infection/src/Performance/Listener/PerformanceLoggerSubscriber.php', - 'PHPInfectionNine.patch' - ); - $this->processPatch( - 'infection/infection/src/Process/Builder/SubscriberBuilder.php', - 'PHPInfectionTen.patch' - ); - } - - /** - * @coversNothing - */ - public function testDoctrineAnnotation(): void - { - $this->processPatch( - 'stesie/phpcs-doctrine-annotation-rules/src/DoctrineAnnotationCodingStandard/Sniffs/Commenting/AbstractDoctrineAnnotationSniff.php', - 'DoctrineAnnotationOne.patch' - ); - $this->processPatch( - 'stesie/phpcs-doctrine-annotation-rules/src/DoctrineAnnotationCodingStandard/Helper/TypeHelper.php', - 'DoctrineAnnotationTwo.patch' - ); - } - -} \ No newline at end of file diff --git a/tests/Integration/CustomReports/PhpCodeSnifferReportTest.php b/tests/Integration/CustomReports/PhpCodeSnifferReportTest.php new file mode 100644 index 0000000..ce8b3a4 --- /dev/null +++ b/tests/Integration/CustomReports/PhpCodeSnifferReportTest.php @@ -0,0 +1,76 @@ + __FILE__, + 'messages' => [ + 1 => [ + 1 => [ + 0 => ['message' => 'Message'], + ], + ], + ], + ]; + + /** + * @var PhpCodeSnifferReport + */ + private PhpCodeSnifferReport $report; + + /** + * @covers \Bruha\CodingStandard\CustomReports\PhpCodeSnifferReport::generateFileReport + */ + public function testGenerateFileReport(): void + { + /** @var File|MockObject $file */ + $file = self::createMock(File::class); + + ob_start(); + self::assertTrue($this->report->generateFileReport(self::REPORT, $file)); + $output = explode(PHP_EOL, (string) ob_get_contents()); + ob_end_clean(); + + self::assertEquals('tests/Integration/CustomReports/PhpCodeSnifferReportTest.php:1: Message', $output[0]); + } + + /** + * @covers \Bruha\CodingStandard\CustomReports\PhpCodeSnifferReport::generate + */ + public function testGenerate(): void + { + ob_start(); + $this->report->generate('tests/Integration/CustomReports/PhpCodeSnifferReportTest.php:1: Message', 1, 1, 1, 1); + $output = explode(PHP_EOL, (string) ob_get_contents()); + ob_end_clean(); + + self::assertEquals('tests/Integration/CustomReports/PhpCodeSnifferReportTest.php:1: Message', $output[0]); + self::assertEquals('Errors: 1', $output[1]); + } + + /** + * + */ + protected function setUp(): void + { + parent::setUp(); + + $this->report = new PhpCodeSnifferReport(); + } + +} \ No newline at end of file diff --git a/tests/Integration/CustomReports/PhpStanReportTest.php b/tests/Integration/CustomReports/PhpStanReportTest.php new file mode 100644 index 0000000..292ab3b --- /dev/null +++ b/tests/Integration/CustomReports/PhpStanReportTest.php @@ -0,0 +1,80 @@ +method('newLine')->willReturnCallback( + static function (): void { + echo PHP_EOL; + } + ); + + /** @var Output|MockObject $output */ + $output = self::createMock(SymfonyOutput::class); + $output->method('getStyle')->willReturn($style); + + ob_start(); + self::assertEquals( + 1, + $this->report->formatErrors( + new AnalysisResult( + [new Error('Message', __FILE__, 1)], + ['Message'], + [], + [], + FALSE, + NULL, + FALSE + ), + $output + ) + ); + $output = explode(PHP_EOL, (string) ob_get_contents()); + ob_end_clean(); + + self::assertEquals('tests/Integration/CustomReports/PhpStanReportTest.php:1: Message', $output[0]); + self::assertEquals('Message', $output[1]); + self::assertEquals('Errors: 2', $output[3]); + } + + /** + * + */ + protected function setUp(): void + { + parent::setUp(); + + $this->report = new PhpStanReport(); + } + +} \ No newline at end of file diff --git a/tests/Integration/CustomRules/AnalyzerTest.php b/tests/Integration/CustomRules/AnalyzerTest.php index d091923..da31515 100644 --- a/tests/Integration/CustomRules/AnalyzerTest.php +++ b/tests/Integration/CustomRules/AnalyzerTest.php @@ -9,12 +9,14 @@ * Class AnalyzerTest * * @package Tests\Integration\CustomRules + * + * @covers \Bruha\CodingStandard\CustomRules\Analyzer */ final class AnalyzerTest extends AbstractTestCase { /** - * @covers Analyzer::phpCodeSniffer + * @covers \Bruha\CodingStandard\CustomRules\Analyzer::phpCodeSniffer */ public function testPhpCodeSniffer(): void { @@ -23,20 +25,15 @@ public function testPhpCodeSniffer(): void $output = explode(PHP_EOL, (string) ob_get_contents()); ob_end_clean(); - self::assertGreaterThan(0, count($output)); - self::assertEquals('', array_pop($output)); - self::assertRegExp( + self::assertMatchesRegularExpression( '/\d+\.\d+s \(100\.000%\): Analyzed \d+ \d+ rows of logs in \d+\.\d+s with \d+\.\d+MB RAM usage/', - (string) array_shift($output) - ); - self::assertRegExp( - '/\d+\.\d+s \(\d+\.\d+%\): .+Sniff/', - (string) array_shift($output) + $output[0] ); + self::assertMatchesRegularExpression('/\d+\.\d+s \(\d+\.\d+%\): .+Sniff/', $output[1]); } /** - * @covers Analyzer::phpUnit + * @covers \Bruha\CodingStandard\CustomRules\Analyzer::phpUnit */ public function testPhpUnit(): void { @@ -45,16 +42,31 @@ public function testPhpUnit(): void $output = explode(PHP_EOL, (string) ob_get_contents()); ob_end_clean(); - self::assertGreaterThan(0, count($output)); - self::assertEquals('', array_pop($output)); - self::assertRegExp( + self::assertMatchesRegularExpression( '/\d+\.\d+s \(100\.000%\): Analyzed \d+ rows of logs in \d+\.\d+s with \d+\.\d+MB RAM usage/', - (string) array_shift($output) - ); - self::assertRegExp( - '/\d+\.\d+s \(\d+\.\d+%\): .+::.+/', - (string) array_shift($output) + $output[0] ); + self::assertMatchesRegularExpression('/\d+\.\d+s \(\d+\.\d+%\): .+::.+/', $output[1]); + } + + /** + * @covers \Bruha\CodingStandard\CustomRules\Analyzer::phpUnitCoverage + */ + public function testPhpUnitCoverage(): void + { + ob_start(); + Analyzer::phpUnitCoverage(50, __DIR__ . '/coverage.xml'); + $output = explode(PHP_EOL, (string) ob_get_contents()); + ob_end_clean(); + + self::assertEquals('', $output[0]); + + ob_start(); + Analyzer::phpUnitCoverage(100, __DIR__ . '/coverage.xml'); + $output = explode(PHP_EOL, (string) ob_get_contents()); + ob_end_clean(); + + self::assertEquals('Minimum required code coverage is 100%, but actual is 50%!', $output[1]); } } \ No newline at end of file diff --git a/tests/Integration/CustomRules/Sniffs/Commenting/ClassSniffTest.php b/tests/Integration/CustomRules/Sniffs/Commenting/ClassSniffTest.php index 9fba256..e2e3770 100644 --- a/tests/Integration/CustomRules/Sniffs/Commenting/ClassSniffTest.php +++ b/tests/Integration/CustomRules/Sniffs/Commenting/ClassSniffTest.php @@ -9,6 +9,9 @@ * Class ClassSniffTest * * @package Tests\Integration\CustomRules\Sniffs\Commenting + * + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\ClassSniff + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\AbstractSniff */ final class ClassSniffTest extends AbstractTestCase { @@ -16,13 +19,10 @@ final class ClassSniffTest extends AbstractTestCase /** * @var string */ - private $sniff = ClassSniff::class; + private string $sniff = ClassSniff::class; /** - * @covers ClassSniff::register - * @covers ClassSniff::process - * @covers ClassSniff::processCommenting - * @covers ClassSniff::replacePlaceholders + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\ClassSniff::process */ public function testSuccess(): void { @@ -32,10 +32,7 @@ public function testSuccess(): void } /** - * @covers ClassSniff::register - * @covers ClassSniff::process - * @covers ClassSniff::processCommenting - * @covers ClassSniff::replacePlaceholders + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\ClassSniff::process */ public function testMissing(): void { @@ -48,7 +45,8 @@ public function testMissing(): void 0, $this->sniff, 'CustomRules.Commenting.Class.Comment', - "Usage of class comment without 'Class ClassSniffMissing' is not allowed." + "Usage of class comment without 'Class ClassSniffMissing' is not allowed.", + 13 ); self::assertNotSuccess( @@ -58,7 +56,8 @@ public function testMissing(): void 1, $this->sniff, 'CustomRules.Commenting.Class.Comment', - "Usage of class comment without '@package Tests\Integration\CustomRules\Sniffs\Commenting\Data' is not allowed." + "Usage of class comment without '@package Tests\Integration\CustomRules\Sniffs\Commenting\Data' is not allowed.", + 13 ); } diff --git a/tests/Integration/CustomRules/Sniffs/Commenting/ConstructorSniffTest.php b/tests/Integration/CustomRules/Sniffs/Commenting/ConstructorSniffTest.php index 341a04b..9203050 100644 --- a/tests/Integration/CustomRules/Sniffs/Commenting/ConstructorSniffTest.php +++ b/tests/Integration/CustomRules/Sniffs/Commenting/ConstructorSniffTest.php @@ -9,6 +9,9 @@ * Class ConstructorSniffTest * * @package Tests\Integration\CustomRules\Sniffs\Commenting + * + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\ConstructorSniff + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\AbstractSniff */ final class ConstructorSniffTest extends AbstractTestCase { @@ -16,13 +19,10 @@ final class ConstructorSniffTest extends AbstractTestCase /** * @var string */ - private $sniff = ConstructorSniff::class; + private string $sniff = ConstructorSniff::class; /** - * @covers ConstructorSniff::register - * @covers ConstructorSniff::process - * @covers ConstructorSniff::processCommenting - * @covers ConstructorSniff::replacePlaceholders + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\ConstructorSniff::process */ public function testSuccess(): void { @@ -32,10 +32,7 @@ public function testSuccess(): void } /** - * @covers ConstructorSniff::register - * @covers ConstructorSniff::process - * @covers ConstructorSniff::processCommenting - * @covers ConstructorSniff::replacePlaceholders + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\ConstructorSniff::process */ public function testMissing(): void { diff --git a/tests/Integration/CustomRules/Sniffs/Commenting/Data/FunctionSniffMissing.php b/tests/Integration/CustomRules/Sniffs/Commenting/Data/FunctionSniffMissing.php index 1779ba7..93c95d3 100644 --- a/tests/Integration/CustomRules/Sniffs/Commenting/Data/FunctionSniffMissing.php +++ b/tests/Integration/CustomRules/Sniffs/Commenting/Data/FunctionSniffMissing.php @@ -12,10 +12,10 @@ final class FunctionSniffMissing /** * @param null|string $stringOne - * @param string|null $stringTwo + * @param string|NULL $stringTwo * @param NULL|string $stringThree * - * @return string|NULL + * @return string|null */ public function missingNull( ?string $stringOne = NULL, diff --git a/tests/Integration/CustomRules/Sniffs/Commenting/Data/FunctionSniffSuccess.php b/tests/Integration/CustomRules/Sniffs/Commenting/Data/FunctionSniffSuccess.php index 7d8e921..a363355 100644 --- a/tests/Integration/CustomRules/Sniffs/Commenting/Data/FunctionSniffSuccess.php +++ b/tests/Integration/CustomRules/Sniffs/Commenting/Data/FunctionSniffSuccess.php @@ -11,11 +11,11 @@ final class FunctionSniffSuccess { /** - * @param string|NULL $stringOne - * @param string|NULL $stringTwo - * @param string|NULL $stringThree + * @param string|null $stringOne + * @param string|null $stringTwo + * @param string|null $stringThree * - * @return string|NULL + * @return string|null */ public function successNull( ?string $stringOne = NULL, diff --git a/tests/Integration/CustomRules/Sniffs/Commenting/FunctionSniffTest.php b/tests/Integration/CustomRules/Sniffs/Commenting/FunctionSniffTest.php index 349f7cf..8156d65 100644 --- a/tests/Integration/CustomRules/Sniffs/Commenting/FunctionSniffTest.php +++ b/tests/Integration/CustomRules/Sniffs/Commenting/FunctionSniffTest.php @@ -9,6 +9,9 @@ * Class FunctionSniffTest * * @package Tests\Integration\CustomRules\Sniffs\Commenting + * + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\FunctionSniff + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\AbstractSniff */ final class FunctionSniffTest extends AbstractTestCase { @@ -16,11 +19,10 @@ final class FunctionSniffTest extends AbstractTestCase /** * @var string */ - private $sniff = FunctionSniff::class; + private string $sniff = FunctionSniff::class; /** - * @covers FunctionSniff::register - * @covers FunctionSniff::process + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\FunctionSniff::process */ public function testSuccess(): void { @@ -30,8 +32,7 @@ public function testSuccess(): void } /** - * @covers FunctionSniff::register - * @covers FunctionSniff::process + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\FunctionSniff::process */ public function testMissing(): void { @@ -44,7 +45,7 @@ public function testMissing(): void 0, $this->sniff, 'CustomRules.Commenting.Function.Comment', - 'Usage of non-rightmost NULL type hint is not allowed.' + 'Usage of non-rightmost null type hint is not allowed.' ); self::assertNotSuccess( @@ -54,7 +55,7 @@ public function testMissing(): void 0, $this->sniff, 'CustomRules.Commenting.Function.Comment', - 'Usage of non-rightmost NULL type hint is not allowed.' + 'Usage of non-rightmost null type hint is not allowed.' ); self::assertNotSuccess( @@ -64,7 +65,7 @@ public function testMissing(): void 0, $this->sniff, 'CustomRules.Commenting.Function.Comment', - 'Usage of non-rightmost NULL type hint is not allowed.' + 'Usage of non-rightmost null type hint is not allowed.' ); } diff --git a/tests/Integration/CustomRules/Sniffs/Commenting/InterfaceSniffTest.php b/tests/Integration/CustomRules/Sniffs/Commenting/InterfaceSniffTest.php index e6fe1c0..99208a0 100644 --- a/tests/Integration/CustomRules/Sniffs/Commenting/InterfaceSniffTest.php +++ b/tests/Integration/CustomRules/Sniffs/Commenting/InterfaceSniffTest.php @@ -9,6 +9,9 @@ * Class InterfaceSniffTest * * @package Tests\Integration\CustomRules\Sniffs\Commenting + * + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\InterfaceSniff + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\AbstractSniff */ final class InterfaceSniffTest extends AbstractTestCase { @@ -16,13 +19,10 @@ final class InterfaceSniffTest extends AbstractTestCase /** * @var string */ - private $sniff = InterfaceSniff::class; + private string $sniff = InterfaceSniff::class; /** - * @covers InterfaceSniff::register - * @covers InterfaceSniff::process - * @covers InterfaceSniff::processCommenting - * @covers InterfaceSniff::replacePlaceholders + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\InterfaceSniff::process */ public function testSuccess(): void { @@ -32,10 +32,7 @@ public function testSuccess(): void } /** - * @covers InterfaceSniff::register - * @covers InterfaceSniff::process - * @covers InterfaceSniff::processCommenting - * @covers InterfaceSniff::replacePlaceholders + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\InterfaceSniff::process */ public function testMissing(): void { diff --git a/tests/Integration/CustomRules/Sniffs/Commenting/TraitSniffTest.php b/tests/Integration/CustomRules/Sniffs/Commenting/TraitSniffTest.php index e59d9a0..7f61fad 100644 --- a/tests/Integration/CustomRules/Sniffs/Commenting/TraitSniffTest.php +++ b/tests/Integration/CustomRules/Sniffs/Commenting/TraitSniffTest.php @@ -9,6 +9,9 @@ * Class TraitSniffTest * * @package Tests\Integration\CustomRules\Sniffs\Commenting + * + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\TraitSniff + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\AbstractSniff */ final class TraitSniffTest extends AbstractTestCase { @@ -16,13 +19,10 @@ final class TraitSniffTest extends AbstractTestCase /** * @var string */ - private $sniff = TraitSniff::class; + private string $sniff = TraitSniff::class; /** - * @covers TraitSniff::register - * @covers TraitSniff::process - * @covers TraitSniff::processCommenting - * @covers TraitSniff::replacePlaceholders + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\TraitSniff::process */ public function testSuccess(): void { @@ -32,10 +32,7 @@ public function testSuccess(): void } /** - * @covers TraitSniff::register - * @covers TraitSniff::process - * @covers TraitSniff::processCommenting - * @covers TraitSniff::replacePlaceholders + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\TraitSniff::process */ public function testMissing(): void { diff --git a/tests/Integration/CustomRules/Sniffs/Functions/Data/AbstractParentSniffSuccess.php b/tests/Integration/CustomRules/Sniffs/Functions/Data/AbstractParentSniffSuccess.php index 7d2a5de..18efc21 100644 --- a/tests/Integration/CustomRules/Sniffs/Functions/Data/AbstractParentSniffSuccess.php +++ b/tests/Integration/CustomRules/Sniffs/Functions/Data/AbstractParentSniffSuccess.php @@ -13,7 +13,7 @@ abstract class AbstractParentSniffSuccess /** * @var string */ - protected $stringOne; + protected string $stringOne; /** * AbstractParentSniffSuccess constructor diff --git a/tests/Integration/CustomRules/Sniffs/Functions/Data/ParentSniffMissing.php b/tests/Integration/CustomRules/Sniffs/Functions/Data/ParentSniffMissing.php deleted file mode 100644 index 8c79964..0000000 --- a/tests/Integration/CustomRules/Sniffs/Functions/Data/ParentSniffMissing.php +++ /dev/null @@ -1,41 +0,0 @@ -stringTwo = $stringTwo; - } - - /** - * @param string $stringOne - * - * @return AbstractParentSniffSuccess - */ - public function setStringOne(string $stringOne): AbstractParentSniffSuccess - { - $stringOne = parent::setStringOne($stringOne); - return $stringOne; - } - -} \ No newline at end of file diff --git a/tests/Integration/CustomRules/Sniffs/Functions/Data/ParentSniffSuccess.php b/tests/Integration/CustomRules/Sniffs/Functions/Data/ParentSniffSuccess.php deleted file mode 100644 index e1ca67b..0000000 --- a/tests/Integration/CustomRules/Sniffs/Functions/Data/ParentSniffSuccess.php +++ /dev/null @@ -1,41 +0,0 @@ -stringTwo = $stringTwo; - } - - /** - * @param string $stringOne - * - * @return AbstractParentSniffSuccess - */ - public function setStringOne(string $stringOne): AbstractParentSniffSuccess - { - return parent::setStringOne($stringOne); - } - -} \ No newline at end of file diff --git a/tests/Integration/CustomRules/Sniffs/Functions/Data/TestSniffMissingTest.php b/tests/Integration/CustomRules/Sniffs/Functions/Data/TestSniffMissingTest.php index 7f98afe..189b124 100644 --- a/tests/Integration/CustomRules/Sniffs/Functions/Data/TestSniffMissingTest.php +++ b/tests/Integration/CustomRules/Sniffs/Functions/Data/TestSniffMissingTest.php @@ -7,7 +7,7 @@ * * @package Tests\Integration\CustomRules\Sniffs\Functions\Data */ -class TestSniffMissingTest +final class TestSniffMissingTest { /** @@ -19,7 +19,7 @@ public function testString(): void } /** - * @covers \Tests\Integration\CustomRules\Sniffs\Functions\Data\TestSniffMissingTest::prepareData + * @covers TestSniffMissingTest::prepareData */ public function testInt(): void { @@ -27,7 +27,7 @@ public function testInt(): void } /** - * @return array + * @return mixed[] */ private function prepareData(): array { diff --git a/tests/Integration/CustomRules/Sniffs/Functions/Data/TestSniffSuccessTest.php b/tests/Integration/CustomRules/Sniffs/Functions/Data/TestSniffSuccessTest.php index 6e272ef..b425ae4 100644 --- a/tests/Integration/CustomRules/Sniffs/Functions/Data/TestSniffSuccessTest.php +++ b/tests/Integration/CustomRules/Sniffs/Functions/Data/TestSniffSuccessTest.php @@ -21,7 +21,7 @@ public function processString(string $string): string } /** - * + * @covers \Tests\Integration\CustomRules\Sniffs\Functions\Data\TestSniffSuccessTest::prepareData */ public function testString(): void { @@ -29,7 +29,7 @@ public function testString(): void } /** - * @return array + * @return mixed[] */ private function prepareData(): array { diff --git a/tests/Integration/CustomRules/Sniffs/Functions/ParentSniffTest.php b/tests/Integration/CustomRules/Sniffs/Functions/ParentSniffTest.php deleted file mode 100644 index 69dedad..0000000 --- a/tests/Integration/CustomRules/Sniffs/Functions/ParentSniffTest.php +++ /dev/null @@ -1,61 +0,0 @@ -processFile(__DIR__ . '/Data/ParentSniffSuccess.php', $this->sniff); - - self::assertSuccess($result); - } - - /** - * @covers ParentSniff::register - * @covers ParentSniff::process - */ - public function testMissing(): void - { - $result = $this->processFile(__DIR__ . '/Data/ParentSniffMissing.php', $this->sniff); - - self::assertNotSuccess( - $result, - 26, - 9, - 0, - $this->sniff, - 'CustomRules.Functions.Parent.NewLine', - 'Usage of parent call without single blank line is not allowed.' - ); - - self::assertNotSuccess( - $result, - 37, - 22, - 0, - $this->sniff, - 'CustomRules.Functions.Parent.NewLine', - 'Usage of parent call without single blank line is not allowed.' - ); - } - -} \ No newline at end of file diff --git a/tests/Integration/CustomRules/Sniffs/Functions/TestSniffTest.php b/tests/Integration/CustomRules/Sniffs/Functions/TestSniffTest.php index 63cfad9..147d55a 100644 --- a/tests/Integration/CustomRules/Sniffs/Functions/TestSniffTest.php +++ b/tests/Integration/CustomRules/Sniffs/Functions/TestSniffTest.php @@ -9,6 +9,9 @@ * Class TestSniffTest * * @package Tests\Integration\CustomRules\Sniffs\Functions + * + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Functions\TestSniff + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\AbstractSniff */ final class TestSniffTest extends AbstractTestCase { @@ -16,12 +19,10 @@ final class TestSniffTest extends AbstractTestCase /** * @var string */ - private $sniff = TestSniff::class; + private string $sniff = TestSniff::class; /** - * @covers TestSniff::register - * @covers TestSniff::process - * @covers TestSniff::getDocumentComment + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Functions\TestSniff::process */ public function testSuccess(): void { @@ -31,24 +32,12 @@ public function testSuccess(): void } /** - * @covers TestSniff::register - * @covers TestSniff::process - * @covers TestSniff::getDocumentComment + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Functions\TestSniff::process */ public function testMissing(): void { $result = $this->processFile(__DIR__ . '/Data/TestSniffMissingTest.php', $this->sniff); - self::assertNotSuccess( - $result, - 10, - 1, - 0, - $this->sniff, - 'CustomRules.Functions.Test.Final', - 'Usage of abstract or normal test class is not allowed.' - ); - self::assertNotSuccess( $result, 13, @@ -66,7 +55,7 @@ public function testMissing(): void 0, $this->sniff, 'CustomRules.Functions.Test.Covers', - 'Usage of @covers annotation with namespace is not allowed.' + 'Usage of @covers annotation without namespace is not allowed.' ); } diff --git a/tests/Integration/CustomRules/Sniffs/Strings/ConcatenationSniffTest.php b/tests/Integration/CustomRules/Sniffs/Strings/ConcatenationSniffTest.php index ffb8d67..42693b5 100644 --- a/tests/Integration/CustomRules/Sniffs/Strings/ConcatenationSniffTest.php +++ b/tests/Integration/CustomRules/Sniffs/Strings/ConcatenationSniffTest.php @@ -9,6 +9,9 @@ * Class ConcatenationSniffTest * * @package Tests\Integration\CustomRules\Sniffs\Strings + * + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Strings\ConcatenationSniff + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Commenting\AbstractSniff */ final class ConcatenationSniffTest extends AbstractTestCase { @@ -16,11 +19,10 @@ final class ConcatenationSniffTest extends AbstractTestCase /** * @var string */ - private $sniff = ConcatenationSniff::class; + private string $sniff = ConcatenationSniff::class; /** - * @covers ConcatenationSniff::register - * @covers ConcatenationSniff::process + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Strings\ConcatenationSniff::process */ public function testSuccess(): void { @@ -30,8 +32,7 @@ public function testSuccess(): void } /** - * @covers ConcatenationSniff::register - * @covers ConcatenationSniff::process + * @covers \Bruha\CodingStandard\CustomRules\Sniffs\Strings\ConcatenationSniff::process */ public function testMissing(): void { diff --git a/tests/Integration/CustomRules/coverage.xml b/tests/Integration/CustomRules/coverage.xml new file mode 100644 index 0000000..8e352aa --- /dev/null +++ b/tests/Integration/CustomRules/coverage.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/tests/PrivateTrait.php b/tests/PrivateTrait.php index fcadf48..6906de2 100644 --- a/tests/PrivateTrait.php +++ b/tests/PrivateTrait.php @@ -66,9 +66,9 @@ protected function setProperty(object $object, string $name, $value): void } /** - * @param object $object - * @param string $name - * @param array $parameters + * @param object $object + * @param string $name + * @param mixed[] $parameters * * @return mixed *