From f483301091b1406d1f253ae7eee4c43ad2fcf116 Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Fri, 7 Feb 2025 14:29:37 +0100 Subject: [PATCH 01/32] php update poc --- Dockerfile | 5 +++-- composer.json | 15 +++++++-------- config/phpcs/ZooRoyal/ruleset.xml | 6 ------ config/phpstan/phpstan.neon | 2 ++ .../FindFilesToCheckCommand.php | 2 +- .../Generic/AbstractToolCommand.php | 2 +- .../JSESLint/JSESLintCommand.php | 2 +- .../JSStyleLint/JSStyleLintCommand.php | 2 +- .../PHPStan/PHPStanConfigGenerator.php | 10 +++++----- .../DisallowMixedParameterTypeHintSniff.php | 2 +- .../CommandLine/Process/ProcessRunnerTest.php | 2 +- .../StaticCodeAnalysis/AllToolsCommandTest.php | 2 +- .../FindFilesToCheckCommandTest.php | 2 +- .../Target/TargetDecoratorTest.php | 2 +- .../JSESLint/TerminalCommandTest.php | 2 +- .../JSStyleLint/TerminalCommandTest.php | 2 +- .../PHPCodeSniffer/TerminalCommandTest.php | 2 +- .../PHPCopyPasteDetector/TerminalCommandTest.php | 2 +- .../PHPMessDetector/TerminalCommandTest.php | 2 +- .../PHPParallelLint/TerminalCommandTest.php | 2 +- .../PHPStan/TerminalCommandTest.php | 2 +- vendor-bin/phpstan/composer.json | 10 +++++----- 22 files changed, 38 insertions(+), 42 deletions(-) diff --git a/Dockerfile b/Dockerfile index dd93462..9af4c72 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,14 @@ -FROM php:8.2-cli-alpine +FROM php:8.4-cli-alpine RUN set -eux ; \ - apk add --no-cache --virtual .composer-rundeps \ + apk add --update --no-cache --virtual .composer-rundeps \ bash \ coreutils \ git \ nodejs \ npm \ openssh-client \ + sqlite-dev \ tini \ unzip \ zip \ diff --git a/composer.json b/composer.json index 11ceceb..92ee664 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "source": "https://github.com/ZooRoyal/coding-standard-source" }, "require": { - "php": "^8.2.0", + "php": "^8.4.0", "ext-json": "*", "ext-xml": "*", "composer-runtime-api": "^2.0", @@ -34,13 +34,12 @@ "nette/neon": "^3.3", "nikic/php-parser": "^4.18", "php-di/php-di": "^7.0.1", - "phpcompatibility/php-compatibility": "dev-develop#a8d67148fb990fbf5c2f6166d54bc91cc01fc655", "slevomat/coding-standard": "^8.10.0", "squizlabs/php_codesniffer": "^3.9.0", - "symfony/console": " ^6.2.8", - "symfony/event-dispatcher": "^6.2.2", - "symfony/filesystem": " ^6.2.0", - "symfony/process": " ^6.2.0", + "symfony/console": " ^7.2.1", + "symfony/event-dispatcher": "^7.2.0", + "symfony/filesystem": " ^7.2.0", + "symfony/process": " ^7.2.0", "thecodingmachine/safe": "^2.5", "webmozart/path-util": "^2.3" }, @@ -48,9 +47,9 @@ "amphp/amp": "^v2.6.2", "amphp/phpunit-util": "^2.0.0", "amphp/process": "^v1.1.4", - "brianium/paratest": "^6.11.0", + "brianium/paratest": "^v6.11.1", "infection/infection": ">=0.27.11", - "mockery/mockery": "^1.6.7", + "mockery/mockery": "^1.6.12", "phpunit/phpunit": "^9.6.16", "roave/security-advisories": "dev-latest", "sebastianknott/hamcrest-object-accessor": "^3.0.0" diff --git a/config/phpcs/ZooRoyal/ruleset.xml b/config/phpcs/ZooRoyal/ruleset.xml index 5b493b8..28b4718 100755 --- a/config/phpcs/ZooRoyal/ruleset.xml +++ b/config/phpcs/ZooRoyal/ruleset.xml @@ -12,12 +12,6 @@ - - - - - - diff --git a/config/phpstan/phpstan.neon b/config/phpstan/phpstan.neon index bcca6f6..6fafd85 100755 --- a/config/phpstan/phpstan.neon +++ b/config/phpstan/phpstan.neon @@ -10,6 +10,8 @@ parameters: reportUnmatchedIgnoredErrors: false ignoreErrors: - '#Function \S+ invoked with [0-9]+ parameters?, [0-9]+ required.#' + - '#Call to static method PHPUnit\\Framework\\Assert::assertInstanceOf\(\) .+ always evaluate to true\.#' exceptions: check: tooWideThrowType: true + treatPhpDocTypesAsCertain: false diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php index c93270e..f78a59a 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php @@ -38,7 +38,7 @@ public function configure(): void /** * Builds InputDefinition for Command * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @SuppressWarnings("PHPMD.ExcessiveMethodLength") */ private function buildInputDefinition(): InputDefinition { diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommand.php index 0eefe2e..c1b6c59 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommand.php @@ -31,7 +31,7 @@ abstract class AbstractToolCommand extends Command * * @throws RuntimeException */ - public function execute(InputInterface $input, OutputInterface $output): ?int + public function execute(InputInterface $input, OutputInterface $output): int { $output->writeln(PHP_EOL . 'Running ' . $this->terminalCommandName . ''); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommand.php index bdbf2f2..f90bdde 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommand.php @@ -38,7 +38,7 @@ protected function configure(): void /** * {@inheritDoc} */ - public function execute(InputInterface $input, OutputInterface $output): ?int + public function execute(InputInterface $input, OutputInterface $output): int { try { $this->terminalCommandFinder->findTerminalCommand('eslint'); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommand.php index ef8063a..8422de4 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommand.php @@ -38,7 +38,7 @@ protected function configure(): void /** * {@inheritDoc} */ - public function execute(InputInterface $input, OutputInterface $output): ?int + public function execute(InputInterface $input, OutputInterface $output): int { try { $this->terminalCommandFinder->findTerminalCommand('stylelint'); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGenerator.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGenerator.php index 922d5ab..1da9eb7 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGenerator.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGenerator.php @@ -45,9 +45,9 @@ public function __construct( /** * This method adds dynamic config values to the given config array. This is needed for the PHPStan config drop-in. * - * @param array|string>|string> $configValues + * @param array|string>|string> $configValues * - * @return array|string>|string> + * @return array|string>|string> */ public function addDynamicConfigValues(array $configValues): array { @@ -88,9 +88,9 @@ private function addFunctionsFiles(array $configValues): array /** * Adds the list of files to be excluded to the config. * - * @param array>> $configValues + * @param array>> $configValues * - * @return array>> + * @return array|string>|string>> */ private function addExcludedFiles(array $configValues): array { @@ -129,7 +129,7 @@ private function addStaticDirectoriesToScan(array $configValues): array * * @param array>> $configValues * - * @return array>> + * @return array|int|string>> */ private function addPhpVersion(array $configValues): array { diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniff.php index e41f333..b0addf2 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniff.php @@ -55,7 +55,7 @@ public function register(): array /** * Check the parameter type hints * - * @param array $parametersTypeHints + * @param array $parametersTypeHints */ private function checkTypeHints( File $phpcsFile, diff --git a/tests/Unit/CommandLine/Process/ProcessRunnerTest.php b/tests/Unit/CommandLine/Process/ProcessRunnerTest.php index f0fb35e..2ea0cad 100644 --- a/tests/Unit/CommandLine/Process/ProcessRunnerTest.php +++ b/tests/Unit/CommandLine/Process/ProcessRunnerTest.php @@ -79,13 +79,13 @@ public function runAsProcessReturningProcessObjectWithArgumentsInjection(): void /** * @test + * @doesNotPerformAssertions */ public function runProcessWithArguments(): void { $result = $this->subject->runAsProcess('git', 'version'); MatcherAssert::assertThat($result, Matchers::startsWith('git version')); - self::assertTrue(true); } /** diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php index 81753ef..c2f83c9 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php @@ -24,7 +24,7 @@ /** * Class AllToolsCommandTest * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings("PHPMD.CouplingBetweenObjects") */ class AllToolsCommandTest extends TestCase { diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php index 97f51d4..d9bcf3f 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php @@ -24,7 +24,7 @@ /** * Class FindFilesToCheckCommandTest * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings("PHPMD.CouplingBetweenObjects") */ class FindFilesToCheckCommandTest extends TestCase { diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php index c9a6e51..a1de3fb 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php @@ -24,7 +24,7 @@ /** * This is a very busy test and needs all the objects ;/ * - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings("PHPMD.CouplingBetweenObjects") */ class TargetDecoratorTest extends TestCase { diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php index a308fe3..959329b 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php @@ -99,7 +99,7 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @SuppressWarnings("PHPMD.ExcessiveMethodLength") * * @return array> */ diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php index 5e07a0d..fa3d30e 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php @@ -94,7 +94,7 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @SuppressWarnings("PHPMD.ExcessiveMethodLength") * * @return array> */ diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php index 6037c01..f694734 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php @@ -100,7 +100,7 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @SuppressWarnings("PHPMD.ExcessiveMethodLength") * * @return array> */ diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php index be89675..8522d4d 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php @@ -100,7 +100,7 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @SuppressWarnings("PHPMD.ExcessiveMethodLength") * * @return array> */ diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php index e89d7ae..1bd66c0 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php @@ -82,7 +82,7 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @SuppressWarnings("PHPMD.ExcessiveMethodLength") * * @return array> */ diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php index dc67471..b3c9862 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php @@ -83,7 +83,7 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @SuppressWarnings("PHPMD.ExcessiveMethodLength") * * @return array> */ diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php index 26e01c3..dc9abbd 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php @@ -96,7 +96,7 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @SuppressWarnings("PHPMD.ExcessiveMethodLength") * * @return array> */ diff --git a/vendor-bin/phpstan/composer.json b/vendor-bin/phpstan/composer.json index be01b3d..21afd57 100644 --- a/vendor-bin/phpstan/composer.json +++ b/vendor-bin/phpstan/composer.json @@ -1,11 +1,11 @@ { "require": { "phpstan/extension-installer": "^1.2", - "phpstan/phpstan": "^1.10.13", - "phpstan/phpstan-doctrine": "^1.3.32", - "phpstan/phpstan-mockery": "^1.1.0", - "phpstan/phpstan-phpunit": "^1.3.3", - "phpstan/phpstan-symfony": "^1.2.20" + "phpstan/phpstan": "^2.1.2", + "phpstan/phpstan-doctrine": "^2.0.1", + "phpstan/phpstan-mockery": "^2.0.0", + "phpstan/phpstan-phpunit": "^2.0.4", + "phpstan/phpstan-symfony": "^2.0.2" }, "config": { "optimize-autoloader": true, From 4acef3f38dfe4c7f06a96fe1f3a573c868b23b4c Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Fri, 7 Feb 2025 15:04:52 +0100 Subject: [PATCH 02/32] Small PHP8.4 feature port --- .../ApplicationLifeCycle/ApplicationFactory.php | 2 +- .../ApplicationLifeCycle/ContainerFactory.php | 2 +- .../EventDispatcherFactory.php | 2 +- .../GitCommandPreconditionChecker.php | 4 +++- .../TerminalCommandPreconditionChecker.php | 4 +++- .../CommandLine/ApplicationLifeCycle/phpdi.php | 4 +--- .../EnhancedFileInfo/EnhancedFileInfoFactory.php | 2 +- .../php/CommandLine/Environment/Environment.php | 2 +- .../Excluders/GitIgnoresExcluder.php | 8 +++++--- .../ExclusionList/Excluders/GitPathsExcluder.php | 2 ++ .../ExclusionList/Excluders/StaticExcluder.php | 6 ++++-- .../ExclusionList/Excluders/TokenExcluder.php | 2 ++ .../ExclusionList/ExclusionListFactory.php | 2 +- .../ExclusionList/ExclusionListSanitizer.php | 2 +- .../FileFinder/AdaptableFileFinder.php | 2 ++ .../FileFinder/AllCheckableFileFinder.php | 2 ++ .../FileFinder/DiffCheckableFileFinder.php | 2 ++ .../CommandLine/FileFinder/GitChangeSetFilter.php | 4 ++-- .../FileSearch/FastCachedFileSearch.php | 2 ++ .../php/CommandLine/Process/ProcessRunner.php | 2 +- .../StaticCodeAnalysis/AllToolsCommand.php | 5 ++++- .../FindFilesToCheckCommand.php | 3 +++ .../Generic/AbstractToolCommand.php | 2 ++ .../Generic/CodingStandardCommandEvent.php | 4 ++++ .../Generic/FixingToolCommand.php | 2 ++ .../Generic/TargetableToolsCommand.php | 2 ++ .../TerminalCommand/AbstractTerminalCommand.php | 3 +++ .../Exclusion/ExclusionDecorator.php | 2 ++ .../Extension/FileExtensionDecorator.php | 2 ++ .../Generic/TerminalCommand/Fix/FixDecorator.php | 2 ++ .../Multiprocess/MultiprocessDecorator.php | 2 ++ .../PhpVersion/ComposerInterpreter.php | 4 ++-- .../PhpVersion/ConstraintToVersionConverter.php | 4 +++- .../PhpVersion/MinimalVersionDecorator.php | 2 ++ .../PhpVersion/VersionDecorator.php | 2 ++ .../Target/ParentBranchGuesser.php | 2 +- .../TerminalCommand/Target/TargetDecorator.php | 2 ++ .../TerminalCommand/TerminalCommandDecorator.php | 2 ++ .../TerminalCommand/TerminalCommandRunner.php | 4 ++-- .../TerminalCommand/Verbose/VerboseDecorator.php | 2 ++ .../ToolCommandFacet/FixableInputFacet.php | 2 ++ .../ToolCommandFacet/TargetableInputFacet.php | 2 ++ .../JSESLint/JSESLintCommand.php | 3 +++ .../JSESLint/TerminalCommand.php | 6 ++++-- .../JSStyleLint/JSStyleLintCommand.php | 3 +++ .../JSStyleLint/TerminalCommand.php | 4 +++- .../PHPCodeSniffer/PHPCodeSnifferCommand.php | 2 ++ .../PHPCodeSniffer/TerminalCommand.php | 4 +++- .../PHPCopyPasteDetectorCommand.php | 2 ++ .../PHPCopyPasteDetector/TerminalCommand.php | 10 ++++++---- .../PHPMessDetector/PHPMessDetectorCommand.php | 2 ++ .../PHPMessDetector/TerminalCommand.php | 4 +++- .../PHPParallelLint/PHPParallelLintCommand.php | 2 ++ .../PHPParallelLint/TerminalCommand.php | 4 +++- .../StaticCodeAnalysis/PHPStan/PHPStanCommand.php | 2 ++ .../PHPStan/PHPStanConfigGenerator.php | 8 ++++---- .../PHPStan/TerminalCommand.php | 4 +++- .../Sniffs/Safe/CheckSafeFunctionUsageSniff.php | 8 ++++++-- .../DisallowMixedParameterTypeHintSniff.php | 10 +++++----- .../DisallowMixedReturnTypeHintSniff.php | 8 ++++---- .../Excluders/ExclusionListSanitizerTest.php | 2 ++ .../Factories/EnhancedFileInfoFactoryTest.php | 2 ++ .../Factories/ExclusionListFactoryTest.php | 3 +++ .../FileFinders/DiffCheckableFileFinderTest.php | 3 +++ .../FileSearch/FastCachedFileSearchTest.php | 2 ++ .../TerminalCommand/TerminalCommandRunnerTest.php | 3 +++ .../Sniffs/Commenting/DocCommentSniffTest.php | 3 +++ .../FunctionCommentThrowTagSniffTest.php | 3 +++ .../Safe/CheckSafeFunctionUsageSniffTest.php | 7 +++++-- .../DisallowMixedParameterTypeHintSniffTest.php | 7 +++++-- .../DisallowMixedReturnTypeHintSniffTest.php | 7 +++++-- tests/System/Complete/GlobalSystemTest.php | 4 ++++ tests/System/Eslint/RunEslintWithConfigTest.php | 15 ++++++++------- .../Safe/CheckSafeFunctionUsageSniffTest.php | 3 +++ tests/Tools/TerminalCommandTestData.php | 2 +- tests/Tools/TestEnvironmentInstallation.php | 6 +++--- .../ApplicationFactoryTest.php | 3 +++ .../ApplicationLifeCycle/ContainerFactoryTest.php | 2 ++ .../EventDispatcherFactoryTest.php | 3 +++ .../GitCommandPreconditionCheckerTest.php | 3 +++ .../TerminalCommandPreconditionCheckerTest.php | 3 +++ .../CommandLine/Environment/EnvironmentTest.php | 3 +++ .../Excluders/CacheKeyGeneratorTest.php | 2 ++ .../Excluders/GitIgnoresExcluderTest.php | 3 +++ .../Excluders/GitPathsExcluderTest.php | 3 +++ .../Excluders/StaticExcluderTest.php | 3 +++ .../ExclusionList/Excluders/TokenExcluderTest.php | 3 +++ .../ExclusionList/ExclusionListFactoryTest.php | 3 +++ .../FileFinder/AdaptableFileFinderTest.php | 3 +++ .../FileFinder/AllCheckableFileFinderTest.php | 3 +++ .../FileFinder/CommitishComparatorTest.php | 3 +++ .../FileFinder/DiffCheckableFileFinderTest.php | 3 +++ .../FileFinder/GitChangeSetFactoryTest.php | 2 ++ .../FileFinder/GitChangeSetFilterTest.php | 3 +++ .../FileFinder/GitInputValidatorTest.php | 3 +++ .../CommandLine/Process/ProcessRunnerTest.php | 3 +++ .../StaticCodeAnalysis/AllToolsCommandTest.php | 7 ++++--- .../FindFilesToCheckCommandTest.php | 3 +++ .../Generic/AbstractToolCommandTest.php | 3 +++ .../Generic/CodingStandardCommandEventTest.php | 3 +++ .../Generic/FixingToolCommandTest.php | 2 ++ .../Generic/NpmAppFinder/NpmCommandFinderTest.php | 3 +++ .../Generic/TargetableToolsCommandTest.php | 2 ++ .../AbstractTerminalCommandTest.php | 3 +++ .../Exclusion/ExclusionDecoratorTest.php | 3 +++ .../Extension/ExtensionDecoratorTest.php | 3 +++ .../TerminalCommand/Fix/FixDecoratorTest.php | 3 +++ .../Multiprocess/MultiprocessDecoratorTest.php | 3 +++ .../PhpVersion/ComposerInterpreterTest.php | 3 +++ .../ConstraintToVersionConverterTest.php | 3 +++ .../PhpVersion/MinimalVersionDecoratorTest.php | 3 +++ .../PhpVersion/PhpVersionConverterTest.php | 3 +++ .../PhpVersion/VersionDecoratorTest.php | 3 +++ .../Target/ParentBranchGuesserTest.php | 3 +++ .../Target/TargetDecoratorTest.php | 3 +++ .../Verbose/VerboseDecoratorTest.php | 3 +++ .../JSESLint/JSESLintCommandTest.php | 5 +++++ .../JSESLint/TerminalCommandTest.php | 11 +++++++---- .../JSStyleLint/JSStyleLintCommandTest.php | 5 +++++ .../JSStyleLint/TerminalCommandTest.php | 11 +++++++---- .../PHPCodeSniffer/PHPCodeSnifferCommandTest.php | 2 ++ .../PHPCodeSniffer/TerminalCommandTest.php | 9 ++++++--- .../PHPCopyPasteDetectorCommandTest.php | 2 ++ .../PHPCopyPasteDetector/TerminalCommandTest.php | 11 +++++++---- .../PHPMessDetectorCommandTest.php | 2 ++ .../PHPMessDetector/TerminalCommandTest.php | 11 +++++++---- .../PHPParallelLintCommandTest.php | 2 ++ .../PHPParallelLint/TerminalCommandTest.php | 11 +++++++---- .../PHPStan/PHPStanCommandTest.php | 2 ++ .../PHPStan/PHPStanConfigGeneratorTest.php | 3 +++ .../PHPStan/TerminalCommandTest.php | 13 ++++++++----- .../Safe/CheckSafeFunctionUsageSniffTest.php | 4 +++- .../DisallowMixedParameterTypeHintSniffTest.php | 3 +++ .../DisallowMixedReturnTypeHintSniffTest.php | 2 ++ 134 files changed, 399 insertions(+), 102 deletions(-) diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php b/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php index cf53840..47a713d 100644 --- a/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php +++ b/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php @@ -26,7 +26,7 @@ class ApplicationFactory { /** @var array */ - private const COMMANDS + private const array COMMANDS = [ AllToolsCommand::class, FindFilesToCheckCommand::class, diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/ContainerFactory.php b/src/main/php/CommandLine/ApplicationLifeCycle/ContainerFactory.php index 50b3127..d281433 100644 --- a/src/main/php/CommandLine/ApplicationLifeCycle/ContainerFactory.php +++ b/src/main/php/CommandLine/ApplicationLifeCycle/ContainerFactory.php @@ -24,7 +24,7 @@ private function __construct() */ public static function getContainerInstance(): Container { - if (self::$container === null) { + if (!self::$container instanceof Container) { self::$container = self::getUnboundContainerInstance(); } diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/EventDispatcherFactory.php b/src/main/php/CommandLine/ApplicationLifeCycle/EventDispatcherFactory.php index 443f4b7..13a7cf8 100644 --- a/src/main/php/CommandLine/ApplicationLifeCycle/EventDispatcherFactory.php +++ b/src/main/php/CommandLine/ApplicationLifeCycle/EventDispatcherFactory.php @@ -23,7 +23,7 @@ class EventDispatcherFactory { /** @var array */ - private const SUBSCRIBERS + private const array SUBSCRIBERS = [ GitCommandPreconditionChecker::class, TerminalCommandPreconditionChecker::class, diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/GitCommandPreconditionChecker.php b/src/main/php/CommandLine/ApplicationLifeCycle/GitCommandPreconditionChecker.php index f0cdd97..30be6c7 100644 --- a/src/main/php/CommandLine/ApplicationLifeCycle/GitCommandPreconditionChecker.php +++ b/src/main/php/CommandLine/ApplicationLifeCycle/GitCommandPreconditionChecker.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle; +use Override; use Symfony\Component\Console\ConsoleEvents; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -18,7 +19,7 @@ */ class GitCommandPreconditionChecker implements EventSubscriberInterface { - private const COMMAND = 'git rev-parse --git-dir'; + private const string COMMAND = 'git rev-parse --git-dir'; private ?int $exitCode = null; @@ -34,6 +35,7 @@ public function __construct(private readonly ProcessRunner $processRunner) * * @return array> */ + #[Override] public static function getSubscribedEvents(): array { return [ConsoleEvents::COMMAND => ['checkForGit', 50]]; diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionChecker.php b/src/main/php/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionChecker.php index 79dd994..d924027 100644 --- a/src/main/php/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionChecker.php +++ b/src/main/php/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionChecker.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle; +use Override; use Symfony\Component\Console\ConsoleEvents; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -19,7 +20,7 @@ class TerminalCommandPreconditionChecker implements EventSubscriberInterface { /** @var array */ - private const COMMANDS = ['git', 'find']; + private const array COMMANDS = ['git', 'find']; /** @var array */ private array $results = []; @@ -36,6 +37,7 @@ public function __construct(private readonly ProcessRunner $processRunner) * * @return array> */ + #[Override] public static function getSubscribedEvents(): array { return [ConsoleEvents::COMMAND => ['checkForTerminalCommands', 100]]; diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php b/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php index 232a3e7..8c496c5 100644 --- a/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php +++ b/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php @@ -30,9 +30,7 @@ FileSearchInterface::class => get(FastCachedFileSearch::class), InputInterface::class => get(ArgvInput::class), OutputInterface::class => get(ConsoleOutput::class), - Parser::class => factory(static function (ContainerInterface $container) { - return $container->get(ParserFactory::class)->create(ParserFactory::PREFER_PHP7); - }), + Parser::class => factory(static fn(ContainerInterface $container) => $container->get(ParserFactory::class)->create(ParserFactory::PREFER_PHP7)), 'excluders' => factory( static function (Container $container) { diff --git a/src/main/php/CommandLine/EnhancedFileInfo/EnhancedFileInfoFactory.php b/src/main/php/CommandLine/EnhancedFileInfo/EnhancedFileInfoFactory.php index 520fd44..253464f 100644 --- a/src/main/php/CommandLine/EnhancedFileInfo/EnhancedFileInfoFactory.php +++ b/src/main/php/CommandLine/EnhancedFileInfo/EnhancedFileInfoFactory.php @@ -14,7 +14,7 @@ class EnhancedFileInfoFactory { /** @var array */ private array $filePool = []; - private string $rootDirectory; + private readonly string $rootDirectory; public function __construct(ProcessRunner $processRunner) { diff --git a/src/main/php/CommandLine/Environment/Environment.php b/src/main/php/CommandLine/Environment/Environment.php index 2c2fd61..94bcd2c 100644 --- a/src/main/php/CommandLine/Environment/Environment.php +++ b/src/main/php/CommandLine/Environment/Environment.php @@ -18,7 +18,7 @@ class Environment { /** @var string */ - private const GIT = 'git'; + private const string GIT = 'git'; public function __construct( private readonly ProcessRunner $processRunner, diff --git a/src/main/php/CommandLine/ExclusionList/Excluders/GitIgnoresExcluder.php b/src/main/php/CommandLine/ExclusionList/Excluders/GitIgnoresExcluder.php index c014f68..b3755d4 100644 --- a/src/main/php/CommandLine/ExclusionList/Excluders/GitIgnoresExcluder.php +++ b/src/main/php/CommandLine/ExclusionList/Excluders/GitIgnoresExcluder.php @@ -4,13 +4,14 @@ namespace Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders; +use Override; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory; use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner; class GitIgnoresExcluder implements ExcluderInterface { - private const GIT_LS_FILES_COMMAND = 'git ls-files -io --exclude-standard --directory'; + private const string GIT_LS_FILES_COMMAND = 'git ls-files -io --exclude-standard --directory'; /** @var array */ private array $cache = []; @@ -32,15 +33,16 @@ public function __construct( * * @return array */ + #[Override] public function getPathsToExclude(array $alreadyExcludedPaths, array $config = []): array { - if (!empty($this->cache)) { + if ($this->cache !== []) { return $this->cache; } $rawIgnoredFoldersAndFilesString = $this->processRunner->runAsProcess(self::GIT_LS_FILES_COMMAND); - if (empty($rawIgnoredFoldersAndFilesString)) { + if ($rawIgnoredFoldersAndFilesString === '' || $rawIgnoredFoldersAndFilesString === '0') { return []; } $rawIgnoredFoldersAndFiles = explode("\n", $rawIgnoredFoldersAndFilesString); diff --git a/src/main/php/CommandLine/ExclusionList/Excluders/GitPathsExcluder.php b/src/main/php/CommandLine/ExclusionList/Excluders/GitPathsExcluder.php index eac46bf..c38bbb2 100644 --- a/src/main/php/CommandLine/ExclusionList/Excluders/GitPathsExcluder.php +++ b/src/main/php/CommandLine/ExclusionList/Excluders/GitPathsExcluder.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders; +use Override; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; @@ -33,6 +34,7 @@ public function __construct( * * @return array */ + #[Override] public function getPathsToExclude(array $alreadyExcludedPaths, array $config = []): array { $cacheKey = $this->cacheKeyGenerator->generateCacheKey($alreadyExcludedPaths); diff --git a/src/main/php/CommandLine/ExclusionList/Excluders/StaticExcluder.php b/src/main/php/CommandLine/ExclusionList/Excluders/StaticExcluder.php index 6d9fb6e..1eb088e 100644 --- a/src/main/php/CommandLine/ExclusionList/Excluders/StaticExcluder.php +++ b/src/main/php/CommandLine/ExclusionList/Excluders/StaticExcluder.php @@ -4,13 +4,14 @@ namespace Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders; +use Override; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory; class StaticExcluder implements ExcluderInterface { /** @var array */ - private const PATHS_TO_EXCLUDE + private const array PATHS_TO_EXCLUDE = [ '.git', '.idea', @@ -41,9 +42,10 @@ public function __construct( * * @return array */ + #[Override] public function getPathsToExclude(array $alreadyExcludedPaths, array $config = []): array { - if (!empty($this->cache)) { + if ($this->cache !== []) { return $this->cache; } diff --git a/src/main/php/CommandLine/ExclusionList/Excluders/TokenExcluder.php b/src/main/php/CommandLine/ExclusionList/Excluders/TokenExcluder.php index 8dcc395..b4c6302 100644 --- a/src/main/php/CommandLine/ExclusionList/Excluders/TokenExcluder.php +++ b/src/main/php/CommandLine/ExclusionList/Excluders/TokenExcluder.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders; +use Override; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; @@ -34,6 +35,7 @@ public function __construct( * * @return array */ + #[Override] public function getPathsToExclude(array $alreadyExcludedPaths, array $config = []): array { if (!isset($config['token'])) { diff --git a/src/main/php/CommandLine/ExclusionList/ExclusionListFactory.php b/src/main/php/CommandLine/ExclusionList/ExclusionListFactory.php index 67a1621..bddf6ac 100644 --- a/src/main/php/CommandLine/ExclusionList/ExclusionListFactory.php +++ b/src/main/php/CommandLine/ExclusionList/ExclusionListFactory.php @@ -48,7 +48,7 @@ public function build(string $token = '', bool $deDuped = true): array $excludedPaths = [...$excludedPaths, ...$newlyFoundExclusionPaths]; } - $filteredArray = $deDuped === true + $filteredArray = $deDuped ? $this->exclusionListSanitizer->sanitizeExclusionList($excludedPaths) : $excludedPaths; diff --git a/src/main/php/CommandLine/ExclusionList/ExclusionListSanitizer.php b/src/main/php/CommandLine/ExclusionList/ExclusionListSanitizer.php index 4eb0be1..c54d49d 100644 --- a/src/main/php/CommandLine/ExclusionList/ExclusionListSanitizer.php +++ b/src/main/php/CommandLine/ExclusionList/ExclusionListSanitizer.php @@ -37,7 +37,7 @@ static function ($value, $key) use ($item, $i): bool { if ($key === $i) { return true; } - return !($value->isSubdirectoryOf($item) || $value->getPathname() === $item->getPathname()); + return !$value->isSubdirectoryOf($item) && $value->getPathname() !== $item->getPathname(); }, ARRAY_FILTER_USE_BOTH, ); diff --git a/src/main/php/CommandLine/FileFinder/AdaptableFileFinder.php b/src/main/php/CommandLine/FileFinder/AdaptableFileFinder.php index bf074c2..b62b497 100644 --- a/src/main/php/CommandLine/FileFinder/AdaptableFileFinder.php +++ b/src/main/php/CommandLine/FileFinder/AdaptableFileFinder.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\FileFinder; +use Override; use Symfony\Component\Console\Exception\InvalidArgumentException; /** @@ -27,6 +28,7 @@ public function __construct( * * @throws InvalidArgumentException */ + #[Override] public function findFiles( array $allowedFileEndings = [], string $exclusionListToken = '', diff --git a/src/main/php/CommandLine/FileFinder/AllCheckableFileFinder.php b/src/main/php/CommandLine/FileFinder/AllCheckableFileFinder.php index 1e141ea..5dbea23 100644 --- a/src/main/php/CommandLine/FileFinder/AllCheckableFileFinder.php +++ b/src/main/php/CommandLine/FileFinder/AllCheckableFileFinder.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\FileFinder; +use Override; use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner; class AllCheckableFileFinder implements FileFinderInterface @@ -23,6 +24,7 @@ public function __construct( * * @param array $allowedFileEndings */ + #[Override] public function findFiles( array $allowedFileEndings = [], string $exclusionListToken = '', diff --git a/src/main/php/CommandLine/FileFinder/DiffCheckableFileFinder.php b/src/main/php/CommandLine/FileFinder/DiffCheckableFileFinder.php index 9b41cf2..c42a69a 100644 --- a/src/main/php/CommandLine/FileFinder/DiffCheckableFileFinder.php +++ b/src/main/php/CommandLine/FileFinder/DiffCheckableFileFinder.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\FileFinder; +use Override; use Symfony\Component\Console\Exception\InvalidArgumentException; use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner; @@ -26,6 +27,7 @@ public function __construct( * * @throws InvalidArgumentException */ + #[Override] public function findFiles( array $allowedFileEndings = [], string $exclusionListToken = '', diff --git a/src/main/php/CommandLine/FileFinder/GitChangeSetFilter.php b/src/main/php/CommandLine/FileFinder/GitChangeSetFilter.php index 11e8a83..e871fc8 100644 --- a/src/main/php/CommandLine/FileFinder/GitChangeSetFilter.php +++ b/src/main/php/CommandLine/FileFinder/GitChangeSetFilter.php @@ -61,7 +61,7 @@ private function mergeLists( array $exclusionList, array $inclusionlist, ): SplObjectStorage { - if (count(array_intersect($exclusionList, $inclusionlist)) !== 0) { + if (array_intersect($exclusionList, $inclusionlist) !== []) { throw new LogicException('Directories can\'t be black- and inclusionlisted at the same time', 1553780055); } $result = new SplObjectStorage(); @@ -101,7 +101,7 @@ private function applyFilters(array $allowedFileEndings, array $files, SplObject */ private function filterByAllowedFileEndings(array &$result, array $allowedFileEndings): void { - if (!empty($allowedFileEndings)) { + if ($allowedFileEndings !== []) { $result = array_filter( $result, static function ($file) use ($allowedFileEndings): bool { diff --git a/src/main/php/CommandLine/FileSearch/FastCachedFileSearch.php b/src/main/php/CommandLine/FileSearch/FastCachedFileSearch.php index 68f77fa..382fec6 100644 --- a/src/main/php/CommandLine/FileSearch/FastCachedFileSearch.php +++ b/src/main/php/CommandLine/FileSearch/FastCachedFileSearch.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\FileSearch; +use Override; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory; @@ -21,6 +22,7 @@ public function __construct(private readonly EnhancedFileInfoFactory $enhancedFi /** * {@inheritDoc} */ + #[Override] public function listFolderFiles( string $fileName, EnhancedFileInfo $path, diff --git a/src/main/php/CommandLine/Process/ProcessRunner.php b/src/main/php/CommandLine/Process/ProcessRunner.php index 535d44f..5b0e048 100644 --- a/src/main/php/CommandLine/Process/ProcessRunner.php +++ b/src/main/php/CommandLine/Process/ProcessRunner.php @@ -36,7 +36,7 @@ public function runAsProcess(string $command, string ...$arguments): string $output = $process->getOutput(); $errorOutput = $process->getErrorOutput(); - $result = empty($errorOutput) + $result = $errorOutput === '' || $errorOutput === '0' ? $output : $output . PHP_EOL . $errorOutput; diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/AllToolsCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/AllToolsCommand.php index 0ebaf23..278b778 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/AllToolsCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/AllToolsCommand.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis; +use Override; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; @@ -15,7 +16,7 @@ class AllToolsCommand extends Command { /** @var array */ - private array $injectedOptions; + private readonly array $injectedOptions; public function __construct( FixableInputFacet $fixableFacet, @@ -29,6 +30,7 @@ public function __construct( parent::__construct($name); } + #[Override] protected function configure(): void { $this->setName('sca:all'); @@ -43,6 +45,7 @@ protected function configure(): void /** * {@inheritdoc} */ + #[Override] public function execute(InputInterface $input, OutputInterface $output): int { $output->writeln('All SCA-Commands will be executed.', OutputInterface::OUTPUT_NORMAL); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php index f78a59a..56bae6f 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis; +use Override; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputInterface; @@ -27,6 +28,7 @@ public function __construct( /** * {@inheritdoc} */ + #[Override] public function configure(): void { $this->setName('find-files'); @@ -94,6 +96,7 @@ private function buildInputDefinition(): InputDefinition /** * {@inheritdoc} */ + #[Override] public function execute(InputInterface $input, OutputInterface $output): int { $exclusionListInput = $input->getOption('exclusionList'); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommand.php index c1b6c59..daeab34 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommand.php @@ -6,6 +6,7 @@ use DI\Attribute\Inject; use Exception; +use Override; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Input\InputInterface; @@ -31,6 +32,7 @@ abstract class AbstractToolCommand extends Command * * @throws RuntimeException */ + #[Override] public function execute(InputInterface $input, OutputInterface $output): int { $output->writeln(PHP_EOL . 'Running ' . $this->terminalCommandName . ''); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEvent.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEvent.php index 796c9cc..5d414c0 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEvent.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEvent.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic; +use Override; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Event\ConsoleEvent; use Symfony\Component\Console\Input\InputInterface; @@ -26,16 +27,19 @@ public function __construct( } /** @return array */ + #[Override] public function getAllowedFileEndings(): array { return $this->allowedFileEndings; } + #[Override] public function getExclusionListToken(): string { return $this->exclusionListToken; } + #[Override] public function getTerminalCommand(): TerminalCommand { return $this->terminalCommand; diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommand.php index 30a5bb6..d809736 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommand.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\ToolCommandFacet\FixableInputFacet; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\ToolCommandFacet\TargetableInputFacet; @@ -17,6 +18,7 @@ public function __construct( parent::__construct($targetableFacet, $name); } + #[Override] protected function configure(): void { parent::configure(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommand.php index 2ab9d23..1d25337 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommand.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\ToolCommandFacet\TargetableInputFacet; abstract class TargetableToolsCommand extends AbstractToolCommand @@ -13,6 +14,7 @@ public function __construct(private readonly TargetableInputFacet $targetableFac parent::__construct($name); } + #[Override] protected function configure(): void { $this->setDefinition($this->targetableFacet->getInputDefinition()); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommand.php index f70abd9..87b6b3d 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommand.php @@ -6,6 +6,7 @@ use DI\Attribute\Inject; use Exception; +use Override; use Stringable; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Output\OutputInterface; @@ -25,6 +26,7 @@ abstract class AbstractTerminalCommand implements TerminalCommand, Stringable * * @return array */ + #[Override] public function toArray(): array { if (!$this->compiled) { @@ -85,6 +87,7 @@ private function runCompilation(): void * Returns the command as sting. This string is supposed to work as input to a * *NIX terminal. */ + #[Override] public function __toString(): string { if (!$this->compiled) { diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecorator.php index cd38d2e..108d5b1 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecorator.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecorator.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Exclusion; +use Override; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\ExclusionList\ExclusionListFactory; @@ -20,6 +21,7 @@ public function __construct( /** * {@inheritDoc} */ + #[Override] public function decorate(DecorateEvent $event): void { $terminalCommand = $event->getTerminalCommand(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/FileExtensionDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/FileExtensionDecorator.php index 74cb3e6..8a96568 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/FileExtensionDecorator.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/FileExtensionDecorator.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Extension; +use Override; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\TerminalCommandDecorator; @@ -13,6 +14,7 @@ class FileExtensionDecorator extends TerminalCommandDecorator /** * {@inheritDoc} */ + #[Override] public function decorate(DecorateEvent $event): void { $terminalCommand = $event->getTerminalCommand(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecorator.php index 4c7b5f5..27c763b 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecorator.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecorator.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Fix; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\TerminalCommandDecorator; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\ToolCommandFacet\FixableInputFacet; @@ -13,6 +14,7 @@ class FixDecorator extends TerminalCommandDecorator /** * {@inheritDoc} */ + #[Override] public function decorate(DecorateEvent $event): void { $terminalCommand = $event->getTerminalCommand(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecorator.php index 1168917..283a89b 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecorator.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecorator.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Multiprocess; +use Override; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent; @@ -17,6 +18,7 @@ public function __construct(private readonly ProcessRunner $processRunner) { } + #[Override] public function decorate(DecorateEvent $event): void { $terminalCommand = $event->getTerminalCommand(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreter.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreter.php index c8434cb..c3759b3 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreter.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreter.php @@ -12,8 +12,8 @@ class ComposerInterpreter { - private const SEARCH_DEPTH_MIN = 1; - private const SEARCH_DEPTH_MAX = 4; + private const int SEARCH_DEPTH_MIN = 1; + private const int SEARCH_DEPTH_MAX = 4; private ?string $cachedMinimalViablePhpVersion = null; private string $cachedMinimalRootPackagePhpVersion; diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverter.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverter.php index 5a52090..359f71b 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverter.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverter.php @@ -20,6 +20,8 @@ public function __construct() '8.0.' => '30', '8.1.' => '28', '8.2.' => '19', + '8.3.' => '16', + '8.4.' => '3', ]; foreach ($phpVersionRanges as $phpVersionString => $phpMaxPatchVersion) { @@ -36,7 +38,7 @@ public function __construct() */ public function extractActualPhpVersion(string $phpVersionConstraint): string { - if (preg_match('/^(\d+)(\.\d+)?(\.\d+)?$/', $phpVersionConstraint, $matches)) { + if (preg_match('/^(\d+)(\.\d+)?(\.\d+)?$/', $phpVersionConstraint, $matches) !== 0) { return $matches[1] . ($matches[2] ?? '.0') . ($matches[3] ?? '.0'); } diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecorator.php index c18c52c..587f613 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecorator.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecorator.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion; +use Override; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\TerminalCommandDecorator; @@ -14,6 +15,7 @@ public function __construct(private readonly ComposerInterpreter $composerInterp { } + #[Override] public function decorate(DecorateEvent $event): void { $terminalCommand = $event->getTerminalCommand(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecorator.php index bd6a3a4..d4c5f44 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecorator.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecorator.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion; +use Override; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\TerminalCommandDecorator; @@ -15,6 +16,7 @@ public function __construct( ) { } + #[Override] public function decorate(DecorateEvent $event): void { $terminalCommand = $event->getTerminalCommand(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesser.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesser.php index a15c558..675badd 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesser.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesser.php @@ -9,7 +9,7 @@ class ParentBranchGuesser { /** @var string */ - private const GIT = 'git'; + private const string GIT = 'git'; public function __construct( private readonly ProcessRunner $processRunner, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecorator.php index a9e36bb..8c4f161 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecorator.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecorator.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target; +use Override; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\FileFinder\AdaptableFileFinder; @@ -23,6 +24,7 @@ public function __construct( /** * {@inheritDoc} */ + #[Override] public function decorate(DecorateEvent $event): void { $terminalCommand = $event->getTerminalCommand(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandDecorator.php index b179c6c..3cc343f 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandDecorator.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandDecorator.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand; +use Override; use Symfony\Component\EventDispatcher\EventSubscriberInterface; abstract class TerminalCommandDecorator implements EventSubscriberInterface @@ -21,6 +22,7 @@ abstract public function decorate(DecorateEvent $event): void; * * @return array> */ + #[Override] final public static function getSubscribedEvents(): array { return [self::EVENT_DECORATE_TERMINAL_COMMAND => ['decorate', 50]]; diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunner.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunner.php index e7edcf0..d24e52c 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunner.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunner.php @@ -21,10 +21,10 @@ public function run(TerminalCommand $terminalCommand): ?int static function () use ($process, $output): void { $errorIncrement = $process->getIncrementalErrorOutput(); $outputIncrement = $process->getIncrementalOutput(); - if (!empty($errorIncrement)) { + if ($errorIncrement !== '' && $errorIncrement !== '0') { $output->write($errorIncrement, false, OutputInterface::OUTPUT_RAW); } - if (!empty($outputIncrement)) { + if ($outputIncrement !== '' && $outputIncrement !== '0') { $output->write($outputIncrement, false, OutputInterface::OUTPUT_RAW); } }, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecorator.php index 9bbfb51..e242c7f 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecorator.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecorator.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose; +use Override; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\TerminalCommandDecorator; @@ -13,6 +14,7 @@ class VerboseDecorator extends TerminalCommandDecorator /** * {@inheritDoc} */ + #[Override] public function decorate(DecorateEvent $event): void { $terminalCommand = $event->getTerminalCommand(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/FixableInputFacet.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/FixableInputFacet.php index 374156a..1566833 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/FixableInputFacet.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/FixableInputFacet.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\ToolCommandFacet; +use Override; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; @@ -14,6 +15,7 @@ class FixableInputFacet implements ToolCommandInputFacet /** * This method returns the input definition needed to know if the user wants something to be fixed. */ + #[Override] public function getInputDefinition(): InputDefinition { return new InputDefinition( diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/TargetableInputFacet.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/TargetableInputFacet.php index e04ebec..f5d3823 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/TargetableInputFacet.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/TargetableInputFacet.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\ToolCommandFacet; +use Override; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; @@ -18,6 +19,7 @@ class TargetableInputFacet implements ToolCommandInputFacet * This method returns the input definition needed to know if the user wants the command to be focused on changed * files. */ + #[Override] public function getInputDefinition(): InputDefinition { return new InputDefinition( diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommand.php index f90bdde..cda919d 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommand.php @@ -6,6 +6,7 @@ use DI\Attribute\Inject; use DI\Container; +use Override; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\FixingToolCommand; @@ -23,6 +24,7 @@ class JSESLintCommand extends FixingToolCommand /** * {@inheritDoc} */ + #[Override] protected function configure(): void { parent::configure(); @@ -38,6 +40,7 @@ protected function configure(): void /** * {@inheritDoc} */ + #[Override] public function execute(InputInterface $input, OutputInterface $output): int { try { diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php index 6df43ee..dbfb99a 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\JSESLint; +use Override; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; @@ -32,7 +33,7 @@ class TerminalCommand extends AbstractTerminalCommand implements use FileExtensionTrait; use VerboseTrait; - private const TEMPLATE + private const string TEMPLATE = 'npx %8$s--no-install eslint %6$s%7$s--no-error-on-unmatched-pattern --no-eslintrc --config %1$s %3$s' . '--ignore-path %2$s %4$s%5$s'; @@ -43,6 +44,7 @@ public function __construct(private readonly Environment $environment) /** * {@inheritDoc} */ + #[Override] protected function compile(): void { $this->validateTargets(); @@ -133,7 +135,7 @@ private function buildTargetingString(): string private function buildFixingString(): string { $fixingString = ''; - if ($this->fixingMode === true) { + if ($this->fixingMode) { $fixingString = '--fix '; } return $fixingString; diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommand.php index 8422de4..aef2b43 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommand.php @@ -6,6 +6,7 @@ use DI\Attribute\Inject; use DI\Container; +use Override; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\FixingToolCommand; @@ -23,6 +24,7 @@ class JSStyleLintCommand extends FixingToolCommand /** * {@inheritDoc} */ + #[Override] protected function configure(): void { parent::configure(); @@ -38,6 +40,7 @@ protected function configure(): void /** * {@inheritDoc} */ + #[Override] public function execute(InputInterface $input, OutputInterface $output): int { try { diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php index a946ff0..69b087c 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\JSStyleLint; +use Override; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; @@ -32,7 +33,7 @@ class TerminalCommand extends AbstractTerminalCommand implements use FileExtensionTrait; use VerboseTrait; - private const TEMPLATE = 'npx %6$s--no-install stylelint %3$s %4$s%5$s--allow-empty-input --config-basedir --config=%1$s%2$s'; + private const string TEMPLATE = 'npx %6$s--no-install stylelint %3$s %4$s%5$s--allow-empty-input --config-basedir --config=%1$s%2$s'; /** * TerminalCommand constructor. @@ -44,6 +45,7 @@ public function __construct(private readonly Environment $environment) /** * {@inheritDoc} */ + #[Override] protected function compile(): void { $this->validateTargets(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommand.php index c97d60f..6728ebd 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommand.php @@ -6,6 +6,7 @@ use DI\Attribute\Inject; use DI\Container; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\FixingToolCommand; class PHPCodeSnifferCommand extends FixingToolCommand @@ -15,6 +16,7 @@ class PHPCodeSnifferCommand extends FixingToolCommand /** @var array */ protected array $allowedFileEndings = ['php']; + #[Override] protected function configure(): void { parent::configure(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php index 4a79636..23c00e8 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCodeSniffer; +use Override; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; @@ -42,7 +43,7 @@ class TerminalCommand extends AbstractTerminalCommand implements use MultiprocessTrait; use MinimalVersionDependentTrait; - private const TEMPLATE = 'php %1$s %5$s%6$s--parallel=%7$d -p --standard=%2$s%3$s%8$s%4$s'; + private const string TEMPLATE = 'php %1$s %5$s%6$s--parallel=%7$d -p --standard=%2$s%3$s%8$s%4$s'; public function __construct( private readonly Environment $environment, @@ -53,6 +54,7 @@ public function __construct( /** * {@inheritDoc} */ + #[Override] protected function compile(): void { $this->validateTargets(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommand.php index 28b7363..e736944 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommand.php @@ -6,6 +6,7 @@ use DI\Attribute\Inject; use DI\Container; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\AbstractToolCommand; class PHPCopyPasteDetectorCommand extends AbstractToolCommand @@ -19,6 +20,7 @@ class PHPCopyPasteDetectorCommand extends AbstractToolCommand /** * {@inheritDoc} */ + #[Override] protected function configure(): void { $this->setName('sca:copy-paste-detect'); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php index a432ace..3f3671b 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCopyPasteDetector; +use Override; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner; @@ -24,8 +25,8 @@ class TerminalCommand extends AbstractTerminalCommand implements use FileExtensionTrait; use TargetTrait; - private const TEMPLATE = 'php %1$s --fuzzy %3$s%2$s%4$s'; - private const STATIC_EXCLUDES + private const string TEMPLATE = 'php %1$s --fuzzy %3$s%2$s%4$s'; + private const array STATIC_EXCLUDES = [ 'custom/plugins/ZRBannerSlider/ZRBannerSlider.php', 'custom/plugins/ZRPreventShipping/ZRPreventShipping.php', @@ -38,6 +39,7 @@ public function __construct(private readonly Environment $environment, private r /** * {@inheritDoc} */ + #[Override] protected function compile(): void { $vendorPath = $this->environment->getVendorDirectory()->getRealPath(); @@ -80,7 +82,7 @@ private function buildExcludingString(): string $finderResult = $this->processRunner->runAsProcess(...$command); - if (!empty($finderResult)) { + if ($finderResult !== '' && $finderResult !== '0') { $finderResultLines = explode(PHP_EOL, trim($finderResult)); } @@ -140,7 +142,7 @@ private function buildTargetingString(): string private function useExclusions(): bool { - return empty($this->targetedFiles); + return $this->targetedFiles === null || $this->targetedFiles === []; } /** diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommand.php index 9be3807..73d0bae 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommand.php @@ -6,6 +6,7 @@ use DI\Attribute\Inject; use DI\Container; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TargetableToolsCommand; class PHPMessDetectorCommand extends TargetableToolsCommand @@ -19,6 +20,7 @@ class PHPMessDetectorCommand extends TargetableToolsCommand /** * {@inheritDoc} */ + #[Override] protected function configure(): void { parent::configure(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php index 50ed08f..e1a18fb 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPMessDetector; +use Override; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\AbstractTerminalCommand; @@ -23,7 +24,7 @@ class TerminalCommand extends AbstractTerminalCommand implements use ExclusionTrait; use FileExtensionTrait; - private const TEMPLATE = 'php %1$s %2$s text %3$s%5$s%4$s'; + private const string TEMPLATE = 'php %1$s %2$s text %3$s%5$s%4$s'; public function __construct(private readonly Environment $environment) { @@ -32,6 +33,7 @@ public function __construct(private readonly Environment $environment) /** * {@inheritDoc} */ + #[Override] protected function compile(): void { $this->validateTargets(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommand.php index caabcb9..316b0a6 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommand.php @@ -6,6 +6,7 @@ use DI\Attribute\Inject; use DI\Container; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TargetableToolsCommand; class PHPParallelLintCommand extends TargetableToolsCommand @@ -18,6 +19,7 @@ class PHPParallelLintCommand extends TargetableToolsCommand /** * {@inheritDoc} */ + #[Override] protected function configure(): void { parent::configure(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php index 5609093..ad0f562 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPParallelLint; +use Override; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\AbstractTerminalCommand; @@ -27,7 +28,7 @@ class TerminalCommand extends AbstractTerminalCommand implements use FileExtensionTrait; use MultiprocessTrait; - private const TEMPLATE = 'php %1$s -j %5$d%2$s%3$s%4$s'; + private const string TEMPLATE = 'php %1$s -j %5$d%2$s%3$s%4$s'; public function __construct(private readonly Environment $environment) { @@ -36,6 +37,7 @@ public function __construct(private readonly Environment $environment) /** * {@inheritDoc} */ + #[Override] protected function compile(): void { $this->validateTargets(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommand.php index b7e2672..ddd50ad 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommand.php @@ -6,6 +6,7 @@ use DI\Attribute\Inject; use DI\Container; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TargetableToolsCommand; class PHPStanCommand extends TargetableToolsCommand @@ -20,6 +21,7 @@ class PHPStanCommand extends TargetableToolsCommand /** * {@inheritDoc} */ + #[Override] protected function configure(): void { parent::configure(); diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGenerator.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGenerator.php index 1da9eb7..c1c3013 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGenerator.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGenerator.php @@ -14,14 +14,14 @@ class PHPStanConfigGenerator { - private const TOOL_FUNCTIONS_FILE_MAPPING + private const array TOOL_FUNCTIONS_FILE_MAPPING = [ 'deployer/deployer' => ['/src/functions.php'], 'hamcrest/hamcrest-php' => ['/hamcrest/Hamcrest.php'], 'mockery/mockery' => ['/library/helpers.php'], 'sebastianknott/hamcrest-object-accessor' => ['/src/functions.php'], ]; - private const STATIC_DIRECTORIES_TO_SCAN + private const array STATIC_DIRECTORIES_TO_SCAN = [ '/Plugins', '/custom/plugins', @@ -29,8 +29,8 @@ class PHPStanConfigGenerator '/vendor', '/vendor-bin', ]; - private const MAX_TMP_RANDOM = 1000000; - private const MIN_TMP_RANDOM = 0; + private const int MAX_TMP_RANDOM = 1000000; + private const int MIN_TMP_RANDOM = 0; public function __construct( private readonly Filesystem $filesystem, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php index f01a5c7..ad8a4a5 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPStan; +use Override; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; @@ -24,7 +25,7 @@ class TerminalCommand extends AbstractTerminalCommand implements use VerboseTrait; use VersionDependentTrait; - private const TEMPLATE = 'php %1$s analyse %4$s--no-progress --error-format=github -c %2$s %3$s'; + private const string TEMPLATE = 'php %1$s analyse %4$s--no-progress --error-format=github -c %2$s %3$s'; public function __construct( private readonly Environment $environment, @@ -34,6 +35,7 @@ public function __construct( /** * {@inheritDoc} */ + #[Override] protected function compile(): void { $this->validateTargets(); diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php index f7d8962..e08125c 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\Safe; +use Override; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; use PhpParser\Node; @@ -22,7 +23,7 @@ class CheckSafeFunctionUsageSniff implements Sniff { /** @var array */ - private array $functionNames; + private readonly array $functionNames; public function __construct() { @@ -33,6 +34,7 @@ public function __construct() // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged $filesUnfiltered = @scandir($path); } catch (DirException) { + $this->functionNames = []; return; } @@ -63,6 +65,7 @@ public function __construct() * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification We must * stay compatible with the interface even if we don't like it. */ + #[Override] public function register(): array { return [ @@ -80,9 +83,10 @@ public function register(): array * * @throws AssertionException */ + #[Override] public function process(File $phpcsFile, $stackPtr): void { - if (!isset($this->functionNames)) { + if ($this->functionNames === []) { throw new AssertionException( 'No function names found! Did you forget to install thecodingmachine/Safe?', 1684240278, diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniff.php index b0addf2..698e570 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniff.php @@ -15,10 +15,10 @@ class DisallowMixedParameterTypeHintSniff { - private const NAME = 'Zooroyal.TypeHints.DisallowMixedParameterTypeHint'; - private const ERROR_CODE = 'MixedParameterTypeHintUsed'; - private const INVALID_TYPE_HINT = 'mixed'; - private const ERROR_MESSAGE_FUNCTION + private const string NAME = 'Zooroyal.TypeHints.DisallowMixedParameterTypeHint'; + private const string ERROR_CODE = 'MixedParameterTypeHintUsed'; + private const string INVALID_TYPE_HINT = 'mixed'; + private const string ERROR_MESSAGE_FUNCTION = 'uses "' . self::INVALID_TYPE_HINT . '" type hint for parameter %s, which is disallowed'; public function process(File $phpcsFile, int $functionPointer): void @@ -30,7 +30,7 @@ public function process(File $phpcsFile, int $functionPointer): void return; } $parametersTypeHints = FunctionHelper::getParametersTypeHints($phpcsFile, $functionPointer); - if (empty($parametersTypeHints)) { + if ($parametersTypeHints === []) { return; } /** @var array $token */ diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniff.php index 7b0658a..5f97264 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniff.php @@ -14,11 +14,11 @@ class DisallowMixedReturnTypeHintSniff { - private const NAME = 'Zooroyal.TypeHints.DisallowMixedReturnTypeHint'; + private const string NAME = 'Zooroyal.TypeHints.DisallowMixedReturnTypeHint'; - private const ERROR_CODE = 'MixedParameterTypeHintUsed'; + private const string ERROR_CODE = 'MixedParameterTypeHintUsed'; - private const INVALID_TYPE_HINT = 'mixed'; + private const string INVALID_TYPE_HINT = 'mixed'; /** @return array */ public function register(): array @@ -38,7 +38,7 @@ public function process(File $phpcsFile, int $pointer): void /** @var int|string $tokenCode */ $tokenCode = $token['code']; $returnTypeHint = $this->getReturnTypeHintByTokenCode($phpcsFile, $pointer, $tokenCode); - if ($returnTypeHint === null) { + if (!$returnTypeHint instanceof TypeHint) { return; } if ($tokenCode === T_FUNCTION) { diff --git a/tests/Functional/CommandLine/ExclusionList/Excluders/ExclusionListSanitizerTest.php b/tests/Functional/CommandLine/ExclusionList/Excluders/ExclusionListSanitizerTest.php index 948485c..f916481 100644 --- a/tests/Functional/CommandLine/ExclusionList/Excluders/ExclusionListSanitizerTest.php +++ b/tests/Functional/CommandLine/ExclusionList/Excluders/ExclusionListSanitizerTest.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\Tests\Functional\CommandLine\ExclusionList\Excluders; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\ExclusionList\ExclusionListSanitizer; @@ -12,6 +13,7 @@ class ExclusionListSanitizerTest extends TestCase { private ExclusionListSanitizer $subject; + #[Override] protected function setUp(): void { $this->subject = new ExclusionListSanitizer(); diff --git a/tests/Functional/CommandLine/Factories/EnhancedFileInfoFactoryTest.php b/tests/Functional/CommandLine/Factories/EnhancedFileInfoFactoryTest.php index b7d8d14..d5a9bbf 100644 --- a/tests/Functional/CommandLine/Factories/EnhancedFileInfoFactoryTest.php +++ b/tests/Functional/CommandLine/Factories/EnhancedFileInfoFactoryTest.php @@ -8,6 +8,7 @@ use Hamcrest\MatcherAssert; use Hamcrest\Matchers as H; use InvalidArgumentException; +use Override; use PHPUnit\Framework\TestCase; use ReflectionClass; use SebastianKnott\HamcrestObjectAccessor\HasProperty; @@ -25,6 +26,7 @@ class EnhancedFileInfoFactoryTest extends TestCase private string $relativeFilePath2; private string $rootDirectory; + #[Override] public function setUp(): void { $container = ContainerFactory::getContainerInstance(); diff --git a/tests/Functional/CommandLine/Factories/ExclusionListFactoryTest.php b/tests/Functional/CommandLine/Factories/ExclusionListFactoryTest.php index 56d7cb1..1e6dd0c 100644 --- a/tests/Functional/CommandLine/Factories/ExclusionListFactoryTest.php +++ b/tests/Functional/CommandLine/Factories/ExclusionListFactoryTest.php @@ -6,6 +6,7 @@ use Hamcrest\MatcherAssert; use Hamcrest\Matchers as H; +use Override; use PHPUnit\Framework\TestCase; use SebastianKnott\HamcrestObjectAccessor\HasProperty; use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory; @@ -18,6 +19,7 @@ class ExclusionListFactoryTest extends TestCase { private ExclusionListFactory $subject; + #[Override] protected function setUp(): void { $forgedGitPath = __DIR__ . '/Fixtures/gitExclude/.git'; @@ -29,6 +31,7 @@ protected function setUp(): void $this->subject = $container->get(ExclusionListFactory::class); } + #[Override] protected function tearDown(): void { rmdir(__DIR__ . '/Fixtures/gitExclude/.git'); diff --git a/tests/Functional/CommandLine/FileFinders/DiffCheckableFileFinderTest.php b/tests/Functional/CommandLine/FileFinders/DiffCheckableFileFinderTest.php index 6c5ffb5..c05b68f 100644 --- a/tests/Functional/CommandLine/FileFinders/DiffCheckableFileFinderTest.php +++ b/tests/Functional/CommandLine/FileFinders/DiffCheckableFileFinderTest.php @@ -8,6 +8,7 @@ use Hamcrest\MatcherAssert; use Hamcrest\Matchers as H; use Mockery; +use Override; use PHPUnit\Framework\TestCase; use SebastianKnott\HamcrestObjectAccessor\HasProperty; use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory; @@ -21,6 +22,7 @@ class DiffCheckableFileFinderTest extends TestCase private array $forgedFileSet; private string $forgedRawDiffUnfilteredString; + #[Override] protected function setUp(): void { parent::setUp(); @@ -38,6 +40,7 @@ protected function setUp(): void . 'topFolder/folder/.dontChangeFiles'; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Functional/CommandLine/FileSearch/FastCachedFileSearchTest.php b/tests/Functional/CommandLine/FileSearch/FastCachedFileSearchTest.php index 4a81096..50b8474 100644 --- a/tests/Functional/CommandLine/FileSearch/FastCachedFileSearchTest.php +++ b/tests/Functional/CommandLine/FileSearch/FastCachedFileSearchTest.php @@ -7,6 +7,7 @@ use Hamcrest\MatcherAssert; use Hamcrest\Matchers; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use SebastianBergmann\Timer\Timer; use SebastianKnott\HamcrestObjectAccessor\HasProperty; @@ -21,6 +22,7 @@ class FastCachedFileSearchTest extends TestCase private EnhancedFileInfoFactory $enhancedFileInfoFactory; private EnhancedFileInfo $forgedPath; + #[Override] public function setUp(): void { $container = ContainerFactory::getUnboundContainerInstance(); diff --git a/tests/Functional/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunnerTest.php b/tests/Functional/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunnerTest.php index ba0bba9..f26838a 100644 --- a/tests/Functional/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunnerTest.php +++ b/tests/Functional/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunnerTest.php @@ -7,6 +7,7 @@ use Hamcrest\Matchers; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\Output; use Symfony\Component\Console\Output\OutputInterface; @@ -23,6 +24,7 @@ class TerminalCommandRunnerTest extends TestCase private OutputInterface $mockedOutput; private ProcessRunner $processRunner; + #[Override] protected function setUp(): void { $this->mockedOutput = Mockery::mock(OutputInterface::class); @@ -31,6 +33,7 @@ protected function setUp(): void $this->subject = new TerminalCommandRunner($this->processRunner, $this->mockedOutput); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentSniffTest.php b/tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentSniffTest.php index e54f033..99cc13a 100644 --- a/tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentSniffTest.php +++ b/tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentSniffTest.php @@ -5,6 +5,7 @@ namespace Zooroyal\CodingStandard\Tests\Functional\Sniffs\PHPCodesniffer\Standards\ZooRoyal\Sniffs\Commenting; use Composer\Autoload\ClassLoader; +use Override; use PHPUnit\Framework\TestCase; use ReflectionClass; use Symfony\Component\Process\Process; @@ -15,6 +16,7 @@ class DocCommentSniffTest extends TestCase /** @var array */ private array $commandPrefix; + #[Override] public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); @@ -24,6 +26,7 @@ public static function setUpBeforeClass(): void require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php'; } + #[Override] protected function setUp(): void { $this->commandPrefix = explode(' ', 'php ' . self::$vendorDir . '/bin/phpcs ' diff --git a/tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniffTest.php b/tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniffTest.php index 0a43d66..600af15 100644 --- a/tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniffTest.php +++ b/tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniffTest.php @@ -5,6 +5,7 @@ namespace Zooroyal\CodingStandard\Tests\Functional\Sniffs\PHPCodesniffer\Standards\ZooRoyal\Sniffs\Commenting; use Composer\Autoload\ClassLoader; +use Override; use PHPUnit\Framework\TestCase; use ReflectionClass; use Symfony\Component\Process\Process; @@ -15,6 +16,7 @@ class FunctionCommentThrowTagSniffTest extends TestCase /** @var array */ private array $commandPrefix; + #[Override] public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); @@ -24,6 +26,7 @@ public static function setUpBeforeClass(): void require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php'; } + #[Override] protected function setUp(): void { $this->commandPrefix = explode(' ', 'vendor/bin/phpcs ' diff --git a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php index 4977a8b..9f4850e 100644 --- a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php +++ b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php @@ -5,19 +5,21 @@ namespace Zooroyal\CodingStandard\Tests\Functional\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\Safe; use Composer\Autoload\ClassLoader; +use Override; use PHPUnit\Framework\TestCase; use ReflectionClass; use Symfony\Component\Process\Process; class CheckSafeFunctionUsageSniffTest extends TestCase { - private const SNIFF_NAME = 'ZooRoyal.Safe.CheckSafeFunctionUsage'; - private const FIXTURE_DIRECTORY = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/fixtures/'; + private const string SNIFF_NAME = 'ZooRoyal.Safe.CheckSafeFunctionUsage'; + private const string FIXTURE_DIRECTORY = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/fixtures/'; private static string $vendorDir; /** @var array */ private array $commandPrefix = []; + #[Override] public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); @@ -27,6 +29,7 @@ public static function setUpBeforeClass(): void require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php'; } + #[Override] protected function setUp(): void { $this->commandPrefix = [ diff --git a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php index 81355df..28b22bc 100644 --- a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php +++ b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php @@ -5,20 +5,22 @@ namespace Zooroyal\CodingStandard\Tests\Functional\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\TypeHints; use Composer\Autoload\ClassLoader; +use Override; use PHPUnit\Framework\TestCase; use ReflectionClass; use Symfony\Component\Process\Process; class DisallowMixedParameterTypeHintSniffTest extends TestCase { - private const SNIFF_NAME = 'Zooroyal.TypeHints.DisallowMixedParameterTypeHint'; + private const string SNIFF_NAME = 'Zooroyal.TypeHints.DisallowMixedParameterTypeHint'; - private const FIXTURE_DIRECTORY = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/Parameter/'; + private const string FIXTURE_DIRECTORY = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/Parameter/'; private static string $vendorDir; /** @var array */ private array $commandPrefix; + #[Override] public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); @@ -28,6 +30,7 @@ public static function setUpBeforeClass(): void require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php'; } + #[Override] protected function setUp(): void { $this->commandPrefix = [ diff --git a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php index 90f80f5..86190d9 100644 --- a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php +++ b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php @@ -5,20 +5,22 @@ namespace Zooroyal\CodingStandard\Tests\Functional\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\TypeHints; use Composer\Autoload\ClassLoader; +use Override; use PHPUnit\Framework\TestCase; use ReflectionClass; use Symfony\Component\Process\Process; class DisallowMixedReturnTypeHintSniffTest extends TestCase { - private const SNIFF_NAME = 'Zooroyal.TypeHints.DisallowMixedReturnTypeHint'; + private const string SNIFF_NAME = 'Zooroyal.TypeHints.DisallowMixedReturnTypeHint'; - private const FIXTURE_DIRECTORY = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/ReturnType/'; + private const string FIXTURE_DIRECTORY = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/ReturnType/'; private static string $vendorDir; /** @var array */ private array $commandPrefix; + #[Override] public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); @@ -28,6 +30,7 @@ public static function setUpBeforeClass(): void require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php'; } + #[Override] protected function setUp(): void { $this->commandPrefix = [ diff --git a/tests/System/Complete/GlobalSystemTest.php b/tests/System/Complete/GlobalSystemTest.php index 90d7f8d..5878394 100644 --- a/tests/System/Complete/GlobalSystemTest.php +++ b/tests/System/Complete/GlobalSystemTest.php @@ -6,6 +6,7 @@ use Hamcrest\MatcherAssert; use Hamcrest\Matchers as H; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Process\Process; @@ -15,6 +16,7 @@ class GlobalSystemTest extends TestCase { private Filesystem $filesystem; + #[Override] public static function setUpBeforeClass(): void { $dockerCheckProcess = new Process(['docker', 'info']); @@ -24,12 +26,14 @@ public static function setUpBeforeClass(): void } } + #[Override] protected function setUp(): void { parent::setUp(); $this->filesystem = new Filesystem(); } + #[Override] public static function tearDownAfterClass(): void { TestEnvironmentInstallation::getInstance()->removeInstallation(); diff --git a/tests/System/Eslint/RunEslintWithConfigTest.php b/tests/System/Eslint/RunEslintWithConfigTest.php index 6d931f4..b9e8174 100644 --- a/tests/System/Eslint/RunEslintWithConfigTest.php +++ b/tests/System/Eslint/RunEslintWithConfigTest.php @@ -9,6 +9,7 @@ use Amp\Promise; use Hamcrest\MatcherAssert; use Hamcrest\Matchers as H; +use Override; use Symfony\Component\Filesystem\Filesystem; use Zooroyal\CodingStandard\Tests\Tools\TestEnvironmentInstallation; @@ -16,19 +17,21 @@ class RunEslintWithConfigTest extends AsyncTestCase { - private const EXPECTED_TS_PROBLEMS = '183 problems'; - private const EXPECTED_JS_PROBLEMS = '183 problems'; - private const ESLINT_COMMAND = 'npx --no-install eslint --config '; - private const ESLINT_CONFIG_FILE = 'vendor/zooroyal/coding-standard-source/config/eslint/eslint.config.js '; + private const string EXPECTED_TS_PROBLEMS = '183 problems'; + private const string EXPECTED_JS_PROBLEMS = '183 problems'; + private const string ESLINT_COMMAND = 'npx --no-install eslint --config '; + private const string ESLINT_CONFIG_FILE = 'vendor/zooroyal/coding-standard-source/config/eslint/eslint.config.js '; private Filesystem $filesystem; + #[Override] protected function setUp(): void { parent::setUp(); $this->filesystem = new Filesystem(); } + #[Override] public static function tearDownAfterClass(): void { TestEnvironmentInstallation::getInstance()->removeInstallation(); @@ -47,7 +50,6 @@ public function runEslintForJSInCleanInstall(): iterable $command = $this->getEslintCommand( 'vendor/zooroyal/coding-standard-source/tests/System/fixtures/eslint/BadCode.js', - $testInstancePath, ); $commandArray = explode(' ', $command); $process = new Process($commandArray, $testInstancePath); @@ -76,7 +78,6 @@ public function runEslintForTSInCleanInstall(): iterable $command = $this->getEslintCommand( 'vendor/zooroyal/coding-standard-source/tests/System/fixtures/eslint/BadCode.ts', - $testInstancePath, ); $commandArray = explode(' ', $command); $process = new Process($commandArray, $testInstancePath); @@ -134,7 +135,7 @@ private function prepareInstallationDirectory(): string return $envInstallationPath; } - private function getEslintCommand(string $fileToCheck, string $testInstancePath): string + private function getEslintCommand(string $fileToCheck): string { return self::ESLINT_COMMAND . self::ESLINT_CONFIG_FILE diff --git a/tests/System/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/System/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php index 492f437..dffd97c 100644 --- a/tests/System/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php +++ b/tests/System/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\Tests\System\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\Safe; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Process\Process; @@ -15,12 +16,14 @@ class CheckSafeFunctionUsageSniffTest extends TestCase { private Filesystem $filesystem; + #[Override] protected function setUp(): void { parent::setUp(); $this->filesystem = new Filesystem(); } + #[Override] public static function tearDownAfterClass(): void { TestEnvironmentInstallation::getInstance()->removeInstallation(); diff --git a/tests/Tools/TerminalCommandTestData.php b/tests/Tools/TerminalCommandTestData.php index f86dabe..09b391c 100644 --- a/tests/Tools/TerminalCommandTestData.php +++ b/tests/Tools/TerminalCommandTestData.php @@ -12,7 +12,7 @@ */ class TerminalCommandTestData { - private string $expectedCommand; + private readonly string $expectedCommand; /** @var array|null */ private ?array $targets = null; private bool $fixingMode = false; diff --git a/tests/Tools/TestEnvironmentInstallation.php b/tests/Tools/TestEnvironmentInstallation.php index 118fbae..c79edb1 100644 --- a/tests/Tools/TestEnvironmentInstallation.php +++ b/tests/Tools/TestEnvironmentInstallation.php @@ -17,10 +17,10 @@ class TestEnvironmentInstallation { private static TestEnvironmentInstallation $instance; - private Filesystem $filesystem; - private string $installationPath; + private readonly Filesystem $filesystem; + private readonly string $installationPath; private string $composerJsonPath = ''; - private string $composerPath; + private readonly string $composerPath; private bool $isInstalled = false; /** diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php index fb214bc..1b199ac 100644 --- a/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php +++ b/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php @@ -8,6 +8,7 @@ use Hamcrest\Matchers; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; @@ -67,6 +68,7 @@ public function build(): void self::assertSame($result->mockery_getName(), $mockedApplication->mockery_getName()); } + #[Override] public function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -77,6 +79,7 @@ public function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/ContainerFactoryTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/ContainerFactoryTest.php index 99e1321..89d495e 100644 --- a/tests/Unit/CommandLine/ApplicationLifeCycle/ContainerFactoryTest.php +++ b/tests/Unit/CommandLine/ApplicationLifeCycle/ContainerFactoryTest.php @@ -8,6 +8,7 @@ use DI\ContainerBuilder; use Hamcrest\Matchers; use Mockery; +use Override; use PHPUnit\Framework\TestCase; use ReflectionClass; use Symfony\Component\Console\Output\OutputInterface; @@ -15,6 +16,7 @@ class ContainerFactoryTest extends TestCase { + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php index 7d6c148..4b195a2 100644 --- a/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php +++ b/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php @@ -7,6 +7,7 @@ use DI\Container; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventDispatcher; use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\EventDispatcherFactory; @@ -65,6 +66,7 @@ public function build(): void self::assertSame($result->mockery_getName(), $mockedEventDispatcher->mockery_getName()); } + #[Override] public function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -73,6 +75,7 @@ public function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/GitCommandPreconditionCheckerTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/GitCommandPreconditionCheckerTest.php index 520cb20..b73cdcd 100644 --- a/tests/Unit/CommandLine/ApplicationLifeCycle/GitCommandPreconditionCheckerTest.php +++ b/tests/Unit/CommandLine/ApplicationLifeCycle/GitCommandPreconditionCheckerTest.php @@ -8,6 +8,7 @@ use Hamcrest\Matchers as H; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\ConsoleEvents; use Symfony\Component\Console\Exception\RuntimeException; @@ -22,6 +23,7 @@ class GitCommandPreconditionCheckerTest extends TestCase /** @var array */ private array $subjectParameters; + #[Override] public function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -30,6 +32,7 @@ public function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionCheckerTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionCheckerTest.php index b0db1c7..aef278b 100644 --- a/tests/Unit/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionCheckerTest.php +++ b/tests/Unit/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionCheckerTest.php @@ -8,6 +8,7 @@ use Hamcrest\Matchers as H; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\ConsoleEvents; use Symfony\Component\Console\Exception\RuntimeException; @@ -24,6 +25,7 @@ class TerminalCommandPreconditionCheckerTest extends TestCase /** @var array */ private array $commandsToCheck = ['git', 'find']; + #[Override] public function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -32,6 +34,7 @@ public function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/Environment/EnvironmentTest.php b/tests/Unit/CommandLine/Environment/EnvironmentTest.php index ba682b7..ff27f7d 100644 --- a/tests/Unit/CommandLine/Environment/EnvironmentTest.php +++ b/tests/Unit/CommandLine/Environment/EnvironmentTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory; @@ -22,6 +23,7 @@ class EnvironmentTest extends TestCase private array $subjectParameters; private MockInterface|EnhancedFileInfo $mockedEnhancedFileInfo; + #[Override] protected function setUp(): void { $this->mockedEnhancedFileInfo = Mockery::mock(EnhancedFileInfo::class); @@ -32,6 +34,7 @@ protected function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/ExclusionList/Excluders/CacheKeyGeneratorTest.php b/tests/Unit/CommandLine/ExclusionList/Excluders/CacheKeyGeneratorTest.php index edfa4a2..8c09d6c 100644 --- a/tests/Unit/CommandLine/ExclusionList/Excluders/CacheKeyGeneratorTest.php +++ b/tests/Unit/CommandLine/ExclusionList/Excluders/CacheKeyGeneratorTest.php @@ -5,6 +5,7 @@ namespace Zooroyal\CodingStandard\Tests\Unit\CommandLine\ExclusionList\Excluders; use Mockery; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders\CacheKeyGenerator; @@ -13,6 +14,7 @@ class CacheKeyGeneratorTest extends TestCase { private CacheKeyGenerator $subject; + #[Override] protected function setUp(): void { $this->subject = new CacheKeyGenerator(); diff --git a/tests/Unit/CommandLine/ExclusionList/Excluders/GitIgnoresExcluderTest.php b/tests/Unit/CommandLine/ExclusionList/Excluders/GitIgnoresExcluderTest.php index fcf729a..e63ccff 100644 --- a/tests/Unit/CommandLine/ExclusionList/Excluders/GitIgnoresExcluderTest.php +++ b/tests/Unit/CommandLine/ExclusionList/Excluders/GitIgnoresExcluderTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory; @@ -20,6 +21,7 @@ class GitIgnoresExcluderTest extends TestCase /** @var array */ private array $subjectParameters; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -29,6 +31,7 @@ protected function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/ExclusionList/Excluders/GitPathsExcluderTest.php b/tests/Unit/CommandLine/ExclusionList/Excluders/GitPathsExcluderTest.php index 41ba411..a2cb27b 100644 --- a/tests/Unit/CommandLine/ExclusionList/Excluders/GitPathsExcluderTest.php +++ b/tests/Unit/CommandLine/ExclusionList/Excluders/GitPathsExcluderTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory; @@ -22,6 +23,7 @@ class GitPathsExcluderTest extends TestCase /** @var array */ private array $subjectParameters; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -35,6 +37,7 @@ protected function setUp(): void ->withNoArgs()->andReturn($this->forgedRootDirectory); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/ExclusionList/Excluders/StaticExcluderTest.php b/tests/Unit/CommandLine/ExclusionList/Excluders/StaticExcluderTest.php index e421136..b70e55f 100644 --- a/tests/Unit/CommandLine/ExclusionList/Excluders/StaticExcluderTest.php +++ b/tests/Unit/CommandLine/ExclusionList/Excluders/StaticExcluderTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory; @@ -18,6 +19,7 @@ class StaticExcluderTest extends TestCase /** @var array */ private array $subjectParameters; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -26,6 +28,7 @@ protected function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/ExclusionList/Excluders/TokenExcluderTest.php b/tests/Unit/CommandLine/ExclusionList/Excluders/TokenExcluderTest.php index e393de0..0f95a2d 100644 --- a/tests/Unit/CommandLine/ExclusionList/Excluders/TokenExcluderTest.php +++ b/tests/Unit/CommandLine/ExclusionList/Excluders/TokenExcluderTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory; @@ -22,6 +23,7 @@ class TokenExcluderTest extends TestCase /** @var array */ private array $subjectParameters; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -35,6 +37,7 @@ protected function setUp(): void ->withNoArgs()->andReturn($this->forgedRootDirectory); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/ExclusionList/ExclusionListFactoryTest.php b/tests/Unit/CommandLine/ExclusionList/ExclusionListFactoryTest.php index 314563d..d0d2d6c 100644 --- a/tests/Unit/CommandLine/ExclusionList/ExclusionListFactoryTest.php +++ b/tests/Unit/CommandLine/ExclusionList/ExclusionListFactoryTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders\ExcluderInterface; @@ -21,6 +22,7 @@ class ExclusionListFactoryTest extends TestCase private array $mockedExcluders; private MockInterface|ExclusionListSanitizer $mockedExclusionListSanitizer; + #[Override] protected function setUp(): void { $this->mockedExcluder1 = Mockery::mock(ExcluderInterface::class); @@ -32,6 +34,7 @@ protected function setUp(): void $this->subject = new ExclusionListFactory($this->mockedExcluders, $this->mockedExclusionListSanitizer); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/FileFinder/AdaptableFileFinderTest.php b/tests/Unit/CommandLine/FileFinder/AdaptableFileFinderTest.php index 47f57f1..0978a38 100644 --- a/tests/Unit/CommandLine/FileFinder/AdaptableFileFinderTest.php +++ b/tests/Unit/CommandLine/FileFinder/AdaptableFileFinderTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Exception\InvalidArgumentException; use Zooroyal\CodingStandard\CommandLine\FileFinder\AdaptableFileFinder; @@ -22,6 +23,7 @@ class AdaptableFileFinderTest extends TestCase private array $subjectParameters; private AdaptableFileFinder $subject; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -30,6 +32,7 @@ protected function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/FileFinder/AllCheckableFileFinderTest.php b/tests/Unit/CommandLine/FileFinder/AllCheckableFileFinderTest.php index a47053a..1324136 100644 --- a/tests/Unit/CommandLine/FileFinder/AllCheckableFileFinderTest.php +++ b/tests/Unit/CommandLine/FileFinder/AllCheckableFileFinderTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\FileFinder\AllCheckableFileFinder; use Zooroyal\CodingStandard\CommandLine\FileFinder\GitChangeSet; @@ -20,6 +21,7 @@ class AllCheckableFileFinderTest extends TestCase private array $subjectParameters; private AllCheckableFileFinder $subject; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -28,6 +30,7 @@ protected function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/FileFinder/CommitishComparatorTest.php b/tests/Unit/CommandLine/FileFinder/CommitishComparatorTest.php index 0843003..2bb0ffd 100644 --- a/tests/Unit/CommandLine/FileFinder/CommitishComparatorTest.php +++ b/tests/Unit/CommandLine/FileFinder/CommitishComparatorTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\FileFinder\CommitishComparator; use Zooroyal\CodingStandard\CommandLine\FileFinder\GitInputValidator; @@ -18,6 +19,7 @@ class CommitishComparatorTest extends TestCase /** @var array|array */ private array $subjectParameters; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -28,6 +30,7 @@ protected function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/FileFinder/DiffCheckableFileFinderTest.php b/tests/Unit/CommandLine/FileFinder/DiffCheckableFileFinderTest.php index d6e745e..a0c9e2b 100644 --- a/tests/Unit/CommandLine/FileFinder/DiffCheckableFileFinderTest.php +++ b/tests/Unit/CommandLine/FileFinder/DiffCheckableFileFinderTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Exception\InvalidArgumentException; use Zooroyal\CodingStandard\CommandLine\FileFinder\DiffCheckableFileFinder; @@ -21,6 +22,7 @@ class DiffCheckableFileFinderTest extends TestCase private array $subjectParameters; private DiffCheckableFileFinder $subject; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -29,6 +31,7 @@ protected function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/FileFinder/GitChangeSetFactoryTest.php b/tests/Unit/CommandLine/FileFinder/GitChangeSetFactoryTest.php index baafe93..00c51c4 100644 --- a/tests/Unit/CommandLine/FileFinder/GitChangeSetFactoryTest.php +++ b/tests/Unit/CommandLine/FileFinder/GitChangeSetFactoryTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory; @@ -18,6 +19,7 @@ class GitChangeSetFactoryTest extends TestCase /** @var array */ private array $subjectParameters; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); diff --git a/tests/Unit/CommandLine/FileFinder/GitChangeSetFilterTest.php b/tests/Unit/CommandLine/FileFinder/GitChangeSetFilterTest.php index 988797b..06e0229 100644 --- a/tests/Unit/CommandLine/FileFinder/GitChangeSetFilterTest.php +++ b/tests/Unit/CommandLine/FileFinder/GitChangeSetFilterTest.php @@ -8,6 +8,7 @@ use Hamcrest\Matchers; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Exception\LogicException; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; @@ -25,6 +26,7 @@ class GitChangeSetFilterTest extends TestCase private string $exclusionlistedDirectory = 'blub'; private string $mockedRootDirectory = '/my/root/directory'; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -34,6 +36,7 @@ protected function setUp(): void $this->subject = $buildFragments['subject']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/FileFinder/GitInputValidatorTest.php b/tests/Unit/CommandLine/FileFinder/GitInputValidatorTest.php index 3fcc6e0..6e6c1f6 100644 --- a/tests/Unit/CommandLine/FileFinder/GitInputValidatorTest.php +++ b/tests/Unit/CommandLine/FileFinder/GitInputValidatorTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Exception\ProcessFailedException; use Zooroyal\CodingStandard\CommandLine\FileFinder\GitInputValidator; @@ -18,6 +19,7 @@ class GitInputValidatorTest extends TestCase private array $subjectParameters; private GitInputValidator $subject; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -26,6 +28,7 @@ protected function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/Process/ProcessRunnerTest.php b/tests/Unit/CommandLine/Process/ProcessRunnerTest.php index 2ea0cad..84ca9a8 100644 --- a/tests/Unit/CommandLine/Process/ProcessRunnerTest.php +++ b/tests/Unit/CommandLine/Process/ProcessRunnerTest.php @@ -7,6 +7,7 @@ use Hamcrest\MatcherAssert; use Hamcrest\Matchers; use Mockery; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Process; @@ -18,11 +19,13 @@ class ProcessRunnerTest extends TestCase { private ProcessRunner $subject; + #[Override] protected function setUp(): void { $this->subject = new ProcessRunner(); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php index c2f83c9..155c636 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php @@ -9,6 +9,7 @@ use Mockery; use Mockery\Matcher\Closure; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; @@ -43,6 +44,7 @@ class AllToolsCommandTest extends TestCase private Application $mockedApplication; private MockInterface|Command $mockedCommand; + #[Override] protected function setUp(): void { $this->mockedInput = Mockery::mock(InputInterface::class); @@ -64,6 +66,7 @@ protected function setUp(): void $this->subject->setApplication($this->mockedApplication); } + #[Override] protected function tearDown(): void { Mockery::close(); @@ -107,9 +110,7 @@ public function executeCallsAllCommands( ->andReturn($optionsAndValues); $this->mockedInput->shouldReceive('getOption') ->andReturnUsing( - static function ($parameter) use ($optionsAndValues) { - return $optionsAndValues[$parameter]; - }, + static fn($parameter) => $optionsAndValues[$parameter], ); $this->mockedOutput->shouldReceive('writeln')->once() diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php index d9bcf3f..ba32239 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php @@ -8,6 +8,7 @@ use Hamcrest\Matchers as H; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputInterface; @@ -38,6 +39,7 @@ class FindFilesToCheckCommandTest extends TestCase private string $expectedResult1 = 'phpunit.xml.dist'; private string $expectedResult2 = 'composer.json'; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -55,6 +57,7 @@ protected function setUp(): void ->withNoArgs()->andReturn($this->expectedResult2); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommandTest.php index e8c6902..237a069 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommandTest.php @@ -8,6 +8,7 @@ use Hamcrest\Matchers as H; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use SebastianKnott\HamcrestObjectAccessor\HasProperty; use Symfony\Component\Console\Input\InputInterface; @@ -37,6 +38,7 @@ abstract class AbstractToolCommandTest extends TestCase protected array $allowedFileEndings; protected TerminalCommand $mockedTerminalCommand; + #[Override] protected function setUp(): void { $this->mockedInput = Mockery::mock(InputInterface::class); @@ -46,6 +48,7 @@ protected function setUp(): void $this->mockedEventDispatcher = Mockery::mock(EventDispatcherInterface::class); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEventTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEventTest.php index 353e5de..a2d3a22 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEventTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEventTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Event\ConsoleEvent; @@ -25,6 +26,7 @@ class CodingStandardCommandEventTest extends TestCase private array $forgedallowedFileEndings; private MockInterface|TerminalCommand $mockedterminalCommand; + #[Override] protected function setUp(): void { $this->mockedCommand = Mockery::mock(Command::class); @@ -43,6 +45,7 @@ protected function setUp(): void ); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommandTest.php index 8fc950b..de2cdde 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommandTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; @@ -24,6 +25,7 @@ abstract class FixingToolCommandTest extends TargetableToolsCommandTest /** @var array */ protected array $mockedFixingArguments = []; + #[Override] protected function setUp(): void { parent::setUp(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/NpmAppFinder/NpmCommandFinderTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/NpmAppFinder/NpmCommandFinderTest.php index 6e0282c..8ef3d81 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/NpmAppFinder/NpmCommandFinderTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/NpmAppFinder/NpmCommandFinderTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Process; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; @@ -20,6 +21,7 @@ class NpmCommandFinderTest extends TestCase /** @var array */ private array $subjectParameters; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -30,6 +32,7 @@ protected function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommandTest.php index ed75bbb..6560307 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommandTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; @@ -24,6 +25,7 @@ abstract class TargetableToolsCommandTest extends AbstractToolCommandTest /** @var array */ protected array $mockedTargetingOptions; + #[Override] protected function setUp(): void { parent::setUp(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommandTest.php index 12e3280..17105a9 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommandTest.php @@ -7,6 +7,7 @@ use Exception; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Output\OutputInterface; @@ -17,6 +18,7 @@ class AbstractTerminalCommandTest extends TestCase private MockInterface|AbstractTerminalCommand $subject; private MockInterface|OutputInterface $mockedOutput; + #[Override] protected function setUp(): void { $this->mockedOutput = Mockery::mock(OutputInterface::class); @@ -26,6 +28,7 @@ protected function setUp(): void $this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput); } + #[Override] public function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecoratorTest.php index ccf9b71..bc47203 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecoratorTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecoratorTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -32,6 +33,7 @@ class ExclusionDecoratorTest extends TestCase /** @var MockInterface|OutputInterface */ private OutputInterface $mockedOutput; + #[Override] protected function setUp(): void { $this->mockedEvent = Mockery::mock(DecorateEvent::class); @@ -50,6 +52,7 @@ protected function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/ExtensionDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/ExtensionDecoratorTest.php index 3abe195..c2ae61f 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/ExtensionDecoratorTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/ExtensionDecoratorTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent; @@ -24,6 +25,7 @@ class ExtensionDecoratorTest extends TestCase /** @var MockInterface|OutputInterface */ private OutputInterface $mockedOutput; + #[Override] protected function setUp(): void { $this->mockedEvent = Mockery::mock(DecorateEvent::class); @@ -35,6 +37,7 @@ protected function setUp(): void $this->subject = new FileExtensionDecorator(); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecoratorTest.php index d3fb760..cd7af38 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecoratorTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecoratorTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -28,6 +29,7 @@ class FixDecoratorTest extends TestCase /** @var MockInterface|OutputInterface */ private OutputInterface $mockedOutput; + #[Override] protected function setUp(): void { $this->mockedEvent = Mockery::mock(DecorateEvent::class); @@ -41,6 +43,7 @@ protected function setUp(): void $this->subject = new FixDecorator(); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecoratorTest.php index 29a6ba0..5e67167 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecoratorTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecoratorTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner; @@ -27,6 +28,7 @@ class MultiprocessDecoratorTest extends TestCase private ProcessRunner $mockedProcessRunner; private MultiprocessDecorator $subject; + #[Override] protected function setUp(): void { $this->mockedEvent = Mockery::mock(DecorateEvent::class); @@ -40,6 +42,7 @@ protected function setUp(): void $this->subject = new MultiprocessDecorator($this->mockedProcessRunner); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreterTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreterTest.php index ab17262..11ff818 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreterTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreterTest.php @@ -7,6 +7,7 @@ use JsonException; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; @@ -25,6 +26,7 @@ class ComposerInterpreterTest extends TestCase private ComposerInterpreter $subject; private FileSearchInterface $mockedFileSearchInterface; + #[Override] protected function setUp(): void { $this->mockedEnvironment = Mockery::mock(Environment::class); @@ -39,6 +41,7 @@ protected function setUp(): void ); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverterTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverterTest.php index 7aeeead..d06f8f6 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverterTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverterTest.php @@ -5,6 +5,7 @@ namespace Zooroyal\CodingStandard\Tests\Unit\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion; use Mockery; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\ConstraintToVersionConverter; @@ -12,11 +13,13 @@ class ConstraintToVersionConverterTest extends TestCase { private ConstraintToVersionConverter $subject; + #[Override] protected function setUp(): void { $this->subject = new ConstraintToVersionConverter(); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecoratorTest.php index 98022aa..527f592 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecoratorTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecoratorTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent; @@ -24,6 +25,7 @@ class MinimalVersionDecoratorTest extends TestCase private MockInterface&OutputInterface $mockedOutput; private MinimalVersionDecorator $subject; + #[Override] protected function setUp(): void { $this->mockedComposerInterpreter = Mockery::mock(ComposerInterpreter::class); @@ -36,6 +38,7 @@ protected function setUp(): void $this->subject = new MinimalVersionDecorator($this->mockedComposerInterpreter); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/PhpVersionConverterTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/PhpVersionConverterTest.php index a6769a3..09852aa 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/PhpVersionConverterTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/PhpVersionConverterTest.php @@ -5,6 +5,7 @@ namespace Zooroyal\CodingStandard\Tests\Unit\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion; use Mockery; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\PhpVersionConverter; @@ -12,11 +13,13 @@ class PhpVersionConverterTest extends TestCase { private PhpVersionConverter $subject; + #[Override] public function tearDown(): void { Mockery::close(); } + #[Override] public function setUp(): void { $this->subject = new PhpVersionConverter(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecoratorTest.php index 601ddf4..1c6b6ff 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecoratorTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecoratorTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent; @@ -23,6 +24,7 @@ class VersionDecoratorTest extends TestCase private MockInterface&OutputInterface $mockedOutput; private VersionDecorator $subject; + #[Override] protected function setUp(): void { $this->mockedEvent = Mockery::mock(DecorateEvent::class); @@ -37,6 +39,7 @@ protected function setUp(): void ); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesserTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesserTest.php index 0c06396..93aa23d 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesserTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesserTest.php @@ -7,6 +7,7 @@ use Hamcrest\Matchers as H; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\ParentBranchGuesser; @@ -18,6 +19,7 @@ class ParentBranchGuesserTest extends TestCase /** @var array|null */ private ?array $subjectParameters = null; + #[Override] protected function setUp(): void { $subjectFactory = new SubjectFactory(); @@ -28,6 +30,7 @@ protected function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php index a1de3fb..a522855 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -43,6 +44,7 @@ class TargetDecoratorTest extends TestCase private array $forgedAllowedFileEndings = ['asd', 'qwe']; private string $forgedExclusionListToken = 'uptiwubti'; + #[Override] protected function setUp(): void { $this->mockedEvent = Mockery::mock(DecorateEvent::class); @@ -63,6 +65,7 @@ protected function setUp(): void $this->subjectParameters = $buildFragments['parameters']; } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecoratorTest.php index 5cebe16..2af7189 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecoratorTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecoratorTest.php @@ -6,6 +6,7 @@ use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -27,6 +28,7 @@ class VerboseDecoratorTest extends TestCase /** @var MockInterface|OutputInterface */ private OutputInterface $mockedOutput; + #[Override] protected function setUp(): void { $this->mockedEvent = Mockery::mock(DecorateEvent::class); @@ -40,6 +42,7 @@ protected function setUp(): void $this->subject = new VerboseDecorator(); } + #[Override] protected function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommandTest.php index e85c83b..3db4c64 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommandTest.php @@ -7,6 +7,7 @@ use DI\Container; use Mockery; use Mockery\MockInterface; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\NpmAppFinder\NpmCommandFinder; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\NpmAppFinder\NpmCommandNotFoundException; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\JSESLint\JSESLintCommand; @@ -18,6 +19,7 @@ class JSESLintCommandTest extends FixingToolCommandTest private Container|MockInterface $mockedContainer; private NpmCommandFinder|MockInterface $mockedTerminalCommandFinder; + #[Override] protected function setUp(): void { $this->terminalCommandName = 'EsLint'; @@ -59,6 +61,7 @@ public function configureSetsCorrectAttributes(): void /** * @test */ + #[Override] public function executeRunsTerminalCommand(): void { $this->mockedTerminalCommandFinder->shouldReceive('findTerminalCommand')->once() @@ -85,6 +88,7 @@ public function executeSkipsCommandIfNotFound(): void /** * @test */ + #[Override] public function executeWrappsException(): void { $this->mockedTerminalCommandFinder->shouldReceive('findTerminalCommand')->once() @@ -95,6 +99,7 @@ public function executeWrappsException(): void /** * @test */ + #[Override] public function executeWarnsAboutNoUsefulFilesToSniff(): void { $this->mockedTerminalCommandFinder->shouldReceive('findTerminalCommand')->once() diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php index 959329b..0831718 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php @@ -8,6 +8,7 @@ use InvalidArgumentException; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; @@ -18,16 +19,17 @@ class TerminalCommandTest extends TestCase { - private const FORGED_PACKAGE_DIRECTORY = '/packageDirectory'; - private const FORGED_RELATIV_ROOT = '.'; - private const FORGED_ABSOLUTE_ROOT = '/RootDirectory'; - private const FORGED_ABSOLUTE_VENDOR = '/RootDirectory/vendor'; + private const string FORGED_PACKAGE_DIRECTORY = '/packageDirectory'; + private const string FORGED_RELATIV_ROOT = '.'; + private const string FORGED_ABSOLUTE_ROOT = '/RootDirectory'; + private const string FORGED_ABSOLUTE_VENDOR = '/RootDirectory/vendor'; private TerminalCommand $subject; private MockInterface|Environment $mockedEnvironment; private MockInterface|OutputInterface $mockedOutput; + #[Override] protected function setUp(): void { $this->mockedEnvironment = Mockery::mock(Environment::class); @@ -44,6 +46,7 @@ protected function setUp(): void $this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput); } + #[Override] public function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommandTest.php index f1593c6..a2871ef 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommandTest.php @@ -7,6 +7,7 @@ use DI\Container; use Mockery; use Mockery\MockInterface; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\NpmAppFinder\NpmCommandFinder; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\NpmAppFinder\NpmCommandNotFoundException; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\JSStyleLint\JSStyleLintCommand; @@ -20,6 +21,7 @@ class JSStyleLintCommandTest extends FixingToolCommandTest /** @var NpmCommandFinder|MockInterface */ private NpmCommandFinder $mockedTerminalCommandFinder; + #[Override] protected function setUp(): void { $this->terminalCommandName = 'StyleLint'; @@ -47,6 +49,7 @@ protected function setUp(): void /** * @test */ + #[Override] public function executeRunsTerminalCommand(): void { $this->mockedTerminalCommandFinder->shouldReceive('findTerminalCommand')->once() @@ -57,6 +60,7 @@ public function executeRunsTerminalCommand(): void /** * @test */ + #[Override] public function executeWrappsException(): void { $this->mockedTerminalCommandFinder->shouldReceive('findTerminalCommand')->once() @@ -97,6 +101,7 @@ public function executeSkipsCommandIfNotFound(): void /** * @test */ + #[Override] public function executeWarnsAboutNoUsefulFilesToSniff(): void { $this->mockedTerminalCommandFinder->shouldReceive('findTerminalCommand')->once() diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php index fa3d30e..8ef8efd 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php @@ -8,6 +8,7 @@ use InvalidArgumentException; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; @@ -18,10 +19,10 @@ class TerminalCommandTest extends TestCase { - private const FORGED_PACKAGE_DIRECTORY = '/packageDirectory'; - private const FORGED_RELATIV_ROOT = '.'; - private const FORGED_ABSOLUTE_ROOT = '/RootDirectory'; - private const FORGED_ABSOLUTE_VENDOR = '/RootDirectory/vendor'; + private const string FORGED_PACKAGE_DIRECTORY = '/packageDirectory'; + private const string FORGED_RELATIV_ROOT = '.'; + private const string FORGED_ABSOLUTE_ROOT = '/RootDirectory'; + private const string FORGED_ABSOLUTE_VENDOR = '/RootDirectory/vendor'; private TerminalCommand $subject; /** @var MockInterface|\Zooroyal\CodingStandard\CommandLine\Environment\Environment */ @@ -29,6 +30,7 @@ class TerminalCommandTest extends TestCase /** @var MockInterface|OutputInterface */ private OutputInterface $mockedOutput; + #[Override] protected function setUp(): void { $this->mockedEnvironment = Mockery::mock(Environment::class); @@ -45,6 +47,7 @@ protected function setUp(): void $this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput); } + #[Override] public function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommandTest.php index d287069..0ef99f8 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommandTest.php @@ -7,6 +7,7 @@ use DI\Container; use Mockery; use Mockery\MockInterface; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCodeSniffer\PHPCodeSnifferCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCodeSniffer\TerminalCommand; use Zooroyal\CodingStandard\Tests\Unit\CommandLine\StaticCodeAnalysis\Generic\FixingToolCommandTest; @@ -16,6 +17,7 @@ class PHPCodeSnifferCommandTest extends FixingToolCommandTest /** @var Container|MockInterface */ private Container $mockedContainer; + #[Override] protected function setUp(): void { $this->terminalCommandName = 'PHP Code Sniffer'; diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php index f694734..2e42003 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php @@ -8,6 +8,7 @@ use InvalidArgumentException; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; @@ -19,15 +20,16 @@ class TerminalCommandTest extends TestCase { - private const FORGED_PACKAGE_DIRECTORY = '/packageDirectory'; - private const FORGED_RELATIV_ROOT = '.'; - private const FORGED_ABSOLUTE_VENDOR = '/vendor'; + private const string FORGED_PACKAGE_DIRECTORY = '/packageDirectory'; + private const string FORGED_RELATIV_ROOT = '.'; + private const string FORGED_ABSOLUTE_VENDOR = '/vendor'; private TerminalCommand $subject; private MockInterface|Environment $mockedEnvironment; private MockInterface|PhpVersionConverter $mockedPhpVersionConverter; private MockInterface|OutputInterface $mockedOutput; + #[Override] protected function setUp(): void { $this->mockedEnvironment = Mockery::mock(Environment::class); @@ -45,6 +47,7 @@ protected function setUp(): void $this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput); } + #[Override] public function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommandTest.php index 6133650..65326b5 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommandTest.php @@ -7,6 +7,7 @@ use DI\Container; use Mockery; use Mockery\MockInterface; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCopyPasteDetector\PHPCopyPasteDetectorCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCopyPasteDetector\TerminalCommand; use Zooroyal\CodingStandard\Tests\Unit\CommandLine\StaticCodeAnalysis\Generic\AbstractToolCommandTest; @@ -16,6 +17,7 @@ class PHPCopyPasteDetectorCommandTest extends AbstractToolCommandTest /** @var Container|MockInterface */ private Container $mockedContainer; + #[Override] protected function setUp(): void { $this->terminalCommandName = 'PHP Copy Paste Detector'; diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php index 8522d4d..107f885 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php @@ -7,6 +7,7 @@ use Hamcrest\Matchers; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; @@ -17,10 +18,10 @@ class TerminalCommandTest extends TestCase { - private const FORGED_PACKAGE_DIRECTORY = '/packageDirectory'; - private const FORGED_RELATIV_ROOT = '.'; - private const FORGED_ABSOLUTE_ROOT = '/RootDirectory'; - private const FORGED_ABSOLUTE_VENDOR = '/vendor'; + private const string FORGED_PACKAGE_DIRECTORY = '/packageDirectory'; + private const string FORGED_RELATIV_ROOT = '.'; + private const string FORGED_ABSOLUTE_ROOT = '/RootDirectory'; + private const string FORGED_ABSOLUTE_VENDOR = '/vendor'; private TerminalCommand $subject; /** @var MockInterface|\Zooroyal\CodingStandard\CommandLine\Environment\Environment */ @@ -30,6 +31,7 @@ class TerminalCommandTest extends TestCase /** @var MockInterface|ProcessRunner */ private ProcessRunner $mockedProcessRunner; + #[Override] protected function setUp(): void { $this->mockedEnvironment = Mockery::mock(Environment::class); @@ -49,6 +51,7 @@ protected function setUp(): void $this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput); } + #[Override] public function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommandTest.php index 466ea04..ab7d807 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommandTest.php @@ -7,6 +7,7 @@ use DI\Container; use Mockery; use Mockery\MockInterface; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPMessDetector\PHPMessDetectorCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPMessDetector\TerminalCommand; use Zooroyal\CodingStandard\Tests\Unit\CommandLine\StaticCodeAnalysis\Generic\TargetableToolsCommandTest; @@ -16,6 +17,7 @@ class PHPMessDetectorCommandTest extends TargetableToolsCommandTest /** @var Container|MockInterface */ private Container $mockedContainer; + #[Override] protected function setUp(): void { $this->terminalCommandName = 'PHP Mess Detector'; diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php index 1bd66c0..79b5387 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php @@ -7,6 +7,7 @@ use Hamcrest\Matchers; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; @@ -17,10 +18,10 @@ class TerminalCommandTest extends TestCase { - private const FORGED_PACKAGE_DIRECTORY = '/packageDirectory'; - private const FORGED_RELATIV_ROOT = '.'; - private const FORGED_ABSOLUTE_ROOT = '/RootDirectory'; - private const FORGED_ABSOLUTE_VENDOR = '/vendor'; + private const string FORGED_PACKAGE_DIRECTORY = '/packageDirectory'; + private const string FORGED_RELATIV_ROOT = '.'; + private const string FORGED_ABSOLUTE_ROOT = '/RootDirectory'; + private const string FORGED_ABSOLUTE_VENDOR = '/vendor'; private TerminalCommand $subject; /** @var MockInterface|Environment */ @@ -28,6 +29,7 @@ class TerminalCommandTest extends TestCase /** @var MockInterface|OutputInterface */ private OutputInterface $mockedOutput; + #[Override] protected function setUp(): void { $this->mockedEnvironment = Mockery::mock(Environment::class); @@ -46,6 +48,7 @@ protected function setUp(): void $this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput); } + #[Override] public function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommandTest.php index 297a9f8..39c67d1 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommandTest.php @@ -7,6 +7,7 @@ use DI\Container; use Mockery; use Mockery\MockInterface; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPParallelLint\PHPParallelLintCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPParallelLint\TerminalCommand; use Zooroyal\CodingStandard\Tests\Unit\CommandLine\StaticCodeAnalysis\Generic\TargetableToolsCommandTest; @@ -16,6 +17,7 @@ class PHPParallelLintCommandTest extends TargetableToolsCommandTest /** @var Container|MockInterface */ private Container $mockedContainer; + #[Override] protected function setUp(): void { $this->terminalCommandName = 'PHP Parallel Lint'; diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php index b3c9862..4b10617 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php @@ -7,6 +7,7 @@ use Hamcrest\Matchers; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; @@ -17,10 +18,10 @@ class TerminalCommandTest extends TestCase { - private const FORGED_PACKAGE_DIRECTORY = '/packageDirectory'; - private const FORGED_RELATIV_ROOT = '.'; - private const FORGED_ABSOLUTE_ROOT = '/RootDirectory'; - private const FORGED_ABSOLUTE_VENDOR = '/vendor'; + private const string FORGED_PACKAGE_DIRECTORY = '/packageDirectory'; + private const string FORGED_RELATIV_ROOT = '.'; + private const string FORGED_ABSOLUTE_ROOT = '/RootDirectory'; + private const string FORGED_ABSOLUTE_VENDOR = '/vendor'; private TerminalCommand $subject; /** @var MockInterface|\Zooroyal\CodingStandard\CommandLine\Environment\Environment */ @@ -28,6 +29,7 @@ class TerminalCommandTest extends TestCase /** @var MockInterface|OutputInterface */ private OutputInterface $mockedOutput; + #[Override] protected function setUp(): void { $this->mockedEnvironment = Mockery::mock(Environment::class); @@ -46,6 +48,7 @@ protected function setUp(): void $this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput); } + #[Override] public function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommandTest.php index 1002e9d..42dd3b9 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommandTest.php @@ -7,6 +7,7 @@ use DI\Container; use Mockery; use Mockery\MockInterface; +use Override; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPStan\PHPStanCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPStan\TerminalCommand; use Zooroyal\CodingStandard\Tests\Unit\CommandLine\StaticCodeAnalysis\Generic\TargetableToolsCommandTest; @@ -16,6 +17,7 @@ class PHPStanCommandTest extends TargetableToolsCommandTest /** @var Container|MockInterface */ private Container $mockedContainer; + #[Override] protected function setUp(): void { $this->terminalCommandName = 'PHPStan'; diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGeneratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGeneratorTest.php index 4e199b5..211ea9d 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGeneratorTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGeneratorTest.php @@ -9,6 +9,7 @@ use Hamcrest\Matchers as H; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; @@ -33,6 +34,7 @@ class PHPStanConfigGeneratorTest extends TestCase /** @var array */ private array $forgedExcludedFilePaths = ['a', 'b']; + #[Override] protected function setUp(): void { $this->mockedFilesystem = Mockery::mock(Filesystem::class); @@ -62,6 +64,7 @@ protected function setUp(): void ); } + #[Override] protected function assertPostConditions(): void { Mockery::close(); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php index dc9abbd..c97b9ee 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php @@ -8,6 +8,7 @@ use InvalidArgumentException; use Mockery; use Mockery\MockInterface; +use Override; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo; @@ -18,11 +19,11 @@ class TerminalCommandTest extends TestCase { - private const PACKAGE_DIRECTORY = '/packageDirectory'; - private const RELATIVE_ROOT = '.'; - private const ABSOLUTE_ROOT = '/RootDirectory'; - private const ABSOLUTE_VENDOR = '/vendor'; - private const ABSOLUTE_CONFIG = '/packageDirectory/config/phpstan/phpstan.neon'; + private const string PACKAGE_DIRECTORY = '/packageDirectory'; + private const string RELATIVE_ROOT = '.'; + private const string ABSOLUTE_ROOT = '/RootDirectory'; + private const string ABSOLUTE_VENDOR = '/vendor'; + private const string ABSOLUTE_CONFIG = '/packageDirectory/config/phpstan/phpstan.neon'; private TerminalCommand $subject; /** @var MockInterface|Environment */ @@ -30,6 +31,7 @@ class TerminalCommandTest extends TestCase /** @var MockInterface|OutputInterface */ private OutputInterface $mockedOutput; + #[Override] protected function setUp(): void { $this->mockedEnvironment = Mockery::mock(Environment::class); @@ -48,6 +50,7 @@ protected function setUp(): void $this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput); } + #[Override] public function tearDown(): void { Mockery::close(); diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php index c06382b..2c43daa 100644 --- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php @@ -6,6 +6,7 @@ use DI\Container; use Mockery; +use Override; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; use PHPUnit\Framework\TestCase; @@ -16,6 +17,7 @@ class CheckSafeFunctionUsageSniffTest extends TestCase { + #[Override] protected function tearDown(): void { Mockery::close(); @@ -37,7 +39,7 @@ public function constructTheSniff(): void * @runInSeparateProcess * @preserveGlobalState disabled */ - public function notFoundSafeLibrarySkippsProcess(): void + public function notFoundSafeLibrarySkipsProcess(): void { $mockedContainerFactory = Mockery::mock('overload:' . ContainerFactory::class); $mockedContainer = Mockery::mock(Container::class); diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php index 62f9cab..906fd30 100644 --- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php @@ -7,6 +7,7 @@ use Hamcrest\Matchers as H; use Mockery; use Mockery\MockInterface; +use Override; use PHP_CodeSniffer\Files\File; use PHPUnit\Framework\TestCase; use SlevomatCodingStandard\Helpers\DocCommentHelper; @@ -23,11 +24,13 @@ class DisallowMixedParameterTypeHintSniffTest extends TestCase private DisallowMixedParameterTypeHintSniff $subject; private string $subjectName = 'Zooroyal.TypeHints.DisallowMixedParameterTypeHint'; + #[Override] protected function setUp(): void { $this->subject = new DisallowMixedParameterTypeHintSniff(); } + #[Override] protected function assertPostConditions(): void { Mockery::close(); diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php index 3f2893c..c5d77b7 100644 --- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php @@ -4,6 +4,7 @@ namespace Zooroyal\CodingStandard\Tests\Unit\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\TypeHints; +use Override; use PHPUnit\Framework\TestCase; use Zooroyal\CodingStandard\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\TypeHints\DisallowMixedReturnTypeHintSniff; @@ -11,6 +12,7 @@ class DisallowMixedReturnTypeHintSniffTest extends TestCase { private DisallowMixedReturnTypeHintSniff $subject; + #[Override] protected function setUp(): void { $this->subject = new DisallowMixedReturnTypeHintSniff(); From 0b6eb9b42a2412c6a9597596fd5ba76c1f97b717 Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Tue, 25 Feb 2025 14:34:20 +0100 Subject: [PATCH 03/32] Ignore error that arrays are not a callable --- config/phpstan/phpstan.neon | 1 + 1 file changed, 1 insertion(+) diff --git a/config/phpstan/phpstan.neon b/config/phpstan/phpstan.neon index 6fafd85..a7ba438 100755 --- a/config/phpstan/phpstan.neon +++ b/config/phpstan/phpstan.neon @@ -11,6 +11,7 @@ parameters: ignoreErrors: - '#Function \S+ invoked with [0-9]+ parameters?, [0-9]+ required.#' - '#Call to static method PHPUnit\\Framework\\Assert::assertInstanceOf\(\) .+ always evaluate to true\.#' + - '#Parameter.*of method.*expects \(?callable.*array.*given\.$#' exceptions: check: tooWideThrowType: true From e1347de1c0de7dc05dc300f9bc8287eabd1d4aa7 Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Tue, 25 Feb 2025 14:41:36 +0100 Subject: [PATCH 04/32] Ignore error that arrays are not a callable --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 82ce106..983f20f 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -47,7 +47,7 @@ jobs: - name: Setup PHP and Composer uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d with: - php-version: '8.2' + php-version: '8.4' extensions: gd tools: cs2pr, composer env: From d1be547faf46c7b0b41b5a6fe540aef0c333ee5e Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Tue, 25 Feb 2025 14:51:23 +0100 Subject: [PATCH 05/32] update php action --- .github/workflows/continuous-integration.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 983f20f..86f2b72 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -45,7 +45,7 @@ jobs: ${{ runner.os }}-codestyle-${{ env.cache-name }}- - name: Setup PHP and Composer - uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d + uses: shivammathur/setup-php@e77cdb393f70751e0417891f9ae9de6a41096210 with: php-version: '8.4' extensions: gd @@ -118,9 +118,9 @@ jobs: ${{ runner.os }}-tests-${{ env.cache-name }}- - name: Setup PHP and Composer - uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d + uses: shivammathur/setup-php@e77cdb393f70751e0417891f9ae9de6a41096210 with: - php-version: '8.2' + php-version: '8.4' tools: composer:${{ matrix.composer_version }} extensions: xdebug env: From c751e83cb5ae4d5a8a6c0109386860acb82714ef Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Tue, 25 Feb 2025 15:00:13 +0100 Subject: [PATCH 06/32] code style --- src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php | 4 +++- .../StaticCodeAnalysis/JSStyleLint/TerminalCommand.php | 3 ++- .../TypeHints/DisallowMixedParameterTypeHintSniffTest.php | 3 ++- .../Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php b/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php index 8c496c5..2882021 100644 --- a/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php +++ b/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php @@ -30,7 +30,9 @@ FileSearchInterface::class => get(FastCachedFileSearch::class), InputInterface::class => get(ArgvInput::class), OutputInterface::class => get(ConsoleOutput::class), - Parser::class => factory(static fn(ContainerInterface $container) => $container->get(ParserFactory::class)->create(ParserFactory::PREFER_PHP7)), + Parser::class => factory( + static fn(ContainerInterface $container) => $container->get(ParserFactory::class)->create(ParserFactory::PREFER_PHP7) + ), 'excluders' => factory( static function (Container $container) { diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php index 69b087c..995e23d 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php @@ -33,7 +33,8 @@ class TerminalCommand extends AbstractTerminalCommand implements use FileExtensionTrait; use VerboseTrait; - private const string TEMPLATE = 'npx %6$s--no-install stylelint %3$s %4$s%5$s--allow-empty-input --config-basedir --config=%1$s%2$s'; + private const string TEMPLATE = + 'npx %6$s--no-install stylelint %3$s %4$s%5$s--allow-empty-input --config-basedir --config=%1$s%2$s'; /** * TerminalCommand constructor. diff --git a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php index 28b22bc..d81204a 100644 --- a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php +++ b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php @@ -14,7 +14,8 @@ class DisallowMixedParameterTypeHintSniffTest extends TestCase { private const string SNIFF_NAME = 'Zooroyal.TypeHints.DisallowMixedParameterTypeHint'; - private const string FIXTURE_DIRECTORY = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/Parameter/'; + private const string FIXTURE_DIRECTORY = + 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/Parameter/'; private static string $vendorDir; /** @var array */ diff --git a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php index 86190d9..d5a6767 100644 --- a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php +++ b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php @@ -14,7 +14,8 @@ class DisallowMixedReturnTypeHintSniffTest extends TestCase { private const string SNIFF_NAME = 'Zooroyal.TypeHints.DisallowMixedReturnTypeHint'; - private const string FIXTURE_DIRECTORY = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/ReturnType/'; + private const string FIXTURE_DIRECTORY = + 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/ReturnType/'; private static string $vendorDir; /** @var array */ From 6b95c2fdf57307002d1af0efc1d8d31b80599b25 Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Tue, 25 Feb 2025 15:05:40 +0100 Subject: [PATCH 07/32] code style --- .../StaticCodeAnalysis/JSStyleLint/TerminalCommand.php | 4 ++-- .../TypeHints/DisallowMixedParameterTypeHintSniffTest.php | 4 ++-- .../Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php index 995e23d..680ee73 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php @@ -33,8 +33,8 @@ class TerminalCommand extends AbstractTerminalCommand implements use FileExtensionTrait; use VerboseTrait; - private const string TEMPLATE = - 'npx %6$s--no-install stylelint %3$s %4$s%5$s--allow-empty-input --config-basedir --config=%1$s%2$s'; + private const string TEMPLATE + = 'npx %6$s--no-install stylelint %3$s %4$s%5$s--allow-empty-input --config-basedir --config=%1$s%2$s'; /** * TerminalCommand constructor. diff --git a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php index d81204a..ad8afa4 100644 --- a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php +++ b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php @@ -14,8 +14,8 @@ class DisallowMixedParameterTypeHintSniffTest extends TestCase { private const string SNIFF_NAME = 'Zooroyal.TypeHints.DisallowMixedParameterTypeHint'; - private const string FIXTURE_DIRECTORY = - 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/Parameter/'; + private const string FIXTURE_DIRECTORY + = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/Parameter/'; private static string $vendorDir; /** @var array */ diff --git a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php index d5a6767..19c02d9 100644 --- a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php +++ b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php @@ -14,8 +14,8 @@ class DisallowMixedReturnTypeHintSniffTest extends TestCase { private const string SNIFF_NAME = 'Zooroyal.TypeHints.DisallowMixedReturnTypeHint'; - private const string FIXTURE_DIRECTORY = - 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/ReturnType/'; + private const string FIXTURE_DIRECTORY + = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/ReturnType/'; private static string $vendorDir; /** @var array */ From 3ba991d48d371f219c26dda7aeb7e7fcf09571e6 Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Wed, 26 Feb 2025 15:06:27 +0100 Subject: [PATCH 08/32] Fix safe version 3 compatibility --- .../Safe/CheckSafeFunctionUsageSniff.php | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php index e08125c..d45217a 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php @@ -16,7 +16,8 @@ use SlevomatCodingStandard\Helpers\UseStatementHelper; use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; - +use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\ComposerInterpreter; +use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\PhpVersionConverter; use function Safe\file_get_contents; use function Safe\scandir; @@ -28,8 +29,14 @@ class CheckSafeFunctionUsageSniff implements Sniff public function __construct() { $container = ContainerFactory::getContainerInstance(); + $composerInterpreter = $container->get(ComposerInterpreter::class); + + $phpversion = $composerInterpreter->getMinimalViablePhpVersion(); + + list($major, $minor) = explode('.', $phpversion); + $environment = $container->get(Environment::class); - $path = $environment->getRootDirectory()->getRealPath() . '/vendor/thecodingmachine/safe/generated/'; + $path = $environment->getRootDirectory()->getRealPath() . '/vendor/thecodingmachine/safe/generated/' . $major . '.' . $minor . '/'; try { // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged $filesUnfiltered = @scandir($path); @@ -49,7 +56,7 @@ public function __construct() $nodeFinder = $container->get(NodeFinder::class); $functions = $nodeFinder->find($ast, static fn(Node $node) => $node instanceof Node\Stmt\Function_); - $functionNamesLocal = array_map(static fn(Node\Stmt\Function_ $node) => (string) $node->name, $functions); + $functionNamesLocal = array_map(static fn(Node\Stmt\Function_ $node) => (string)$node->name, $functions); $functionNames = [...$functionNames, ...$functionNamesLocal]; } @@ -117,13 +124,6 @@ private function assertNextTokenParenthesisOpener(File $phpcsFile, int $stackPtr } } - private function assertFunctionProvidedBySafe(string $functionName): void - { - if (!in_array($functionName, $this->functionNames, true)) { - throw new AssertionException('Function ' . $functionName . ' not found in Safe!', 1684230170); - } - } - private function assertGlobalFunctionCall(File $phpcsFile, int $stackPtr): void { $previousPointer = TokenHelper::findPreviousEffective($phpcsFile, $stackPtr - 1); @@ -138,6 +138,13 @@ private function assertGlobalFunctionCall(File $phpcsFile, int $stackPtr): void } } + private function assertFunctionProvidedBySafe(string $functionName): void + { + if (!in_array($functionName, $this->functionNames, true)) { + throw new AssertionException('Function ' . $functionName . ' not found in Safe!', 1684230170); + } + } + private function assertFunctionUnused(File $phpcsFile, string $functionName): void { $usesSearchResult = UseStatementHelper::getFileUseStatements($phpcsFile); From 015d094264d31235291f9e750d7418c9a2c5bb92 Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Wed, 26 Feb 2025 15:37:13 +0100 Subject: [PATCH 09/32] Replace deprecated Sniff --- composer.json | 6 +++--- config/phpcs/ZooRoyal/ruleset.xml | 12 ++++++++++-- config/phpmd/phpmd.xml | 2 +- .../php/CommandLine/ApplicationLifeCycle/phpdi.php | 7 ++++++- .../Sniffs/Safe/CheckSafeFunctionUsageSniff.php | 7 ++++--- .../Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php | 4 ++++ 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 92ee664..b5f8577 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "composer/semver": "^3.4", "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", "nette/neon": "^3.3", - "nikic/php-parser": "^4.18", + "nikic/php-parser": "^5.4.0", "php-di/php-di": "^7.0.1", "slevomat/coding-standard": "^8.10.0", "squizlabs/php_codesniffer": "^3.9.0", @@ -40,7 +40,7 @@ "symfony/event-dispatcher": "^7.2.0", "symfony/filesystem": " ^7.2.0", "symfony/process": " ^7.2.0", - "thecodingmachine/safe": "^2.5", + "thecodingmachine/safe": "^3.0.1", "webmozart/path-util": "^2.3" }, "require-dev": { @@ -48,7 +48,7 @@ "amphp/phpunit-util": "^2.0.0", "amphp/process": "^v1.1.4", "brianium/paratest": "^v6.11.1", - "infection/infection": ">=0.27.11", + "infection/infection": ">=0.29.12", "mockery/mockery": "^1.6.12", "phpunit/phpunit": "^9.6.16", "roave/security-advisories": "dev-latest", diff --git a/config/phpcs/ZooRoyal/ruleset.xml b/config/phpcs/ZooRoyal/ruleset.xml index 28b4718..ea26960 100755 --- a/config/phpcs/ZooRoyal/ruleset.xml +++ b/config/phpcs/ZooRoyal/ruleset.xml @@ -225,9 +225,17 @@ - + + + + + + + + - + + diff --git a/config/phpmd/phpmd.xml b/config/phpmd/phpmd.xml index bfa62ff..affb193 100644 --- a/config/phpmd/phpmd.xml +++ b/config/phpmd/phpmd.xml @@ -6,7 +6,7 @@ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> ZooRoyal Ruleset for PHP MessDetector - + diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php b/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php index 2882021..9d2ae6f 100644 --- a/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php +++ b/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php @@ -5,6 +5,7 @@ use DI\Container; use PhpParser\Parser; use PhpParser\ParserFactory; +use PhpParser\PhpVersion; use Psr\Container\ContainerInterface; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\ArgvInput; @@ -20,6 +21,7 @@ use Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders\TokenExcluder; use Zooroyal\CodingStandard\CommandLine\FileSearch\FastCachedFileSearch; use Zooroyal\CodingStandard\CommandLine\FileSearch\FileSearchInterface; +use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\ComposerInterpreter; use function DI\factory; use function DI\get; @@ -31,7 +33,10 @@ InputInterface::class => get(ArgvInput::class), OutputInterface::class => get(ConsoleOutput::class), Parser::class => factory( - static fn(ContainerInterface $container) => $container->get(ParserFactory::class)->create(ParserFactory::PREFER_PHP7) + static function (ContainerInterface $container, ComposerInterpreter $composerInterpreter) { + $phpversion = PhpVersion::fromString($composerInterpreter->getMinimalViablePhpVersion()); + return $container->get(ParserFactory::class)->createForVersion($phpversion); + } ), 'excluders' => factory( diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php index d45217a..76595e3 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php @@ -17,7 +17,7 @@ use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\ComposerInterpreter; -use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\PhpVersionConverter; + use function Safe\file_get_contents; use function Safe\scandir; @@ -36,7 +36,8 @@ public function __construct() list($major, $minor) = explode('.', $phpversion); $environment = $container->get(Environment::class); - $path = $environment->getRootDirectory()->getRealPath() . '/vendor/thecodingmachine/safe/generated/' . $major . '.' . $minor . '/'; + $path = $environment->getRootDirectory()->getRealPath() . '/vendor/thecodingmachine/safe/generated/' + . $major . '.' . $minor . '/'; try { // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged $filesUnfiltered = @scandir($path); @@ -56,7 +57,7 @@ public function __construct() $nodeFinder = $container->get(NodeFinder::class); $functions = $nodeFinder->find($ast, static fn(Node $node) => $node instanceof Node\Stmt\Function_); - $functionNamesLocal = array_map(static fn(Node\Stmt\Function_ $node) => (string)$node->name, $functions); + $functionNamesLocal = array_map(static fn(Node\Stmt\Function_ $node) => (string) $node->name, $functions); $functionNames = [...$functionNames, ...$functionNamesLocal]; } diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php index 2c43daa..7d2426e 100644 --- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php @@ -13,6 +13,7 @@ use RuntimeException; use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; +use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\ComposerInterpreter; use Zooroyal\CodingStandard\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\Safe\CheckSafeFunctionUsageSniff; class CheckSafeFunctionUsageSniffTest extends TestCase @@ -45,10 +46,13 @@ public function notFoundSafeLibrarySkipsProcess(): void $mockedContainer = Mockery::mock(Container::class); $mockedEnvironment = Mockery::mock(Environment::class); $mockedFile = Mockery::mock(File::class); + $mockedComposerInterpreter = Mockery::mock(ComposerInterpreter::class); $mockedContainerFactory->expects()->getContainerInstance()->andReturn($mockedContainer); $mockedContainer->expects()->get(Environment::class)->andReturn($mockedEnvironment); + $mockedContainer->expects()->get(ComposerInterpreter::class)->andReturn($mockedComposerInterpreter); $mockedEnvironment->shouldReceive('getRootDirectory->getRealPath')->andReturn('/foo/bar'); + $mockedComposerInterpreter->expects()->getMinimalViablePhpVersion()->andReturn('8.4.3'); $this->expectExceptionObject( new RuntimeException( From f0edbe3ef627de7084962acc1eb2e1223fe707de Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Wed, 26 Feb 2025 16:26:56 +0100 Subject: [PATCH 10/32] replace more rules from phpmd by phpstan and phpcs --- config/phpcs/ZooRoyal/ruleset.xml | 19 ++++++++++++------- config/phpmd/phpmd.xml | 12 ++---------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/config/phpcs/ZooRoyal/ruleset.xml b/config/phpcs/ZooRoyal/ruleset.xml index ea26960..15f296e 100755 --- a/config/phpcs/ZooRoyal/ruleset.xml +++ b/config/phpcs/ZooRoyal/ruleset.xml @@ -72,6 +72,7 @@ + @@ -115,6 +116,11 @@ + + + + + @@ -188,6 +194,11 @@ + + + + + @@ -225,13 +236,6 @@ - - - - - - - @@ -240,6 +244,7 @@ + - - - - - - - + @@ -46,6 +39,5 @@ - - + From 3ad27d6f900cd0c18436215e4e63390132996e96 Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Wed, 26 Feb 2025 17:21:42 +0100 Subject: [PATCH 11/32] Replaced some phpmd rules and fixed cs --- config/phpcs/ZooRoyal/ruleset.xml | 5 +++++ config/phpstan/phpstan.neon | 1 + .../StaticCodeAnalysis/FindFilesToCheckCommand.php | 3 +-- .../StaticCodeAnalysis/JSESLint/TerminalCommandTest.php | 3 +-- .../StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php | 3 +-- .../PHPCodeSniffer/TerminalCommandTest.php | 3 +-- .../PHPCopyPasteDetector/TerminalCommandTest.php | 3 +-- .../PHPMessDetector/TerminalCommandTest.php | 3 +-- .../PHPParallelLint/TerminalCommandTest.php | 3 +-- .../StaticCodeAnalysis/PHPStan/TerminalCommandTest.php | 3 +-- 10 files changed, 14 insertions(+), 16 deletions(-) diff --git a/config/phpcs/ZooRoyal/ruleset.xml b/config/phpcs/ZooRoyal/ruleset.xml index 15f296e..eec26a7 100755 --- a/config/phpcs/ZooRoyal/ruleset.xml +++ b/config/phpcs/ZooRoyal/ruleset.xml @@ -147,6 +147,11 @@ + + + + + diff --git a/config/phpstan/phpstan.neon b/config/phpstan/phpstan.neon index a7ba438..5c1bd01 100755 --- a/config/phpstan/phpstan.neon +++ b/config/phpstan/phpstan.neon @@ -12,6 +12,7 @@ parameters: - '#Function \S+ invoked with [0-9]+ parameters?, [0-9]+ required.#' - '#Call to static method PHPUnit\\Framework\\Assert::assertInstanceOf\(\) .+ always evaluate to true\.#' - '#Parameter.*of method.*expects \(?callable.*array.*given\.$#' + - '#Call to an undefined method Mockery\\ExpectationInterface\|Mockery\\ExpectsHigherOrderMessage#' exceptions: check: tooWideThrowType: true diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php index 56bae6f..6458440 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php @@ -39,9 +39,8 @@ public function configure(): void /** * Builds InputDefinition for Command - * - * @SuppressWarnings("PHPMD.ExcessiveMethodLength") */ + // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength private function buildInputDefinition(): InputDefinition { return new InputDefinition( diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php index 0831718..30ed30c 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php @@ -102,10 +102,9 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings("PHPMD.ExcessiveMethodLength") - * * @return array> */ + // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength public function terminalCommandCompilationDataProvider(): array { return [ diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php index 8ef8efd..2e4813b 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php @@ -97,10 +97,9 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings("PHPMD.ExcessiveMethodLength") - * * @return array> */ + // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength public function terminalCommandCompilationDataProvider(): array { return [ diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php index 2e42003..9aa14e9 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php @@ -103,10 +103,9 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings("PHPMD.ExcessiveMethodLength") - * * @return array> */ + // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength public function terminalCommandCompilationDataProvider(): array { $mockedEnhancedFileInfo1 = Mockery::mock(EnhancedFileInfo::class); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php index 107f885..fa6dea3 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php @@ -103,10 +103,9 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings("PHPMD.ExcessiveMethodLength") - * * @return array> */ + // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength public function terminalCommandCompilationDataProvider(): array { return [ diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php index 79b5387..a89961a 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php @@ -85,10 +85,9 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings("PHPMD.ExcessiveMethodLength") - * * @return array> */ + // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength public function terminalCommandCompilationDataProvider(): array { $mockedEnhancedFileInfoExcluded1 = Mockery::mock(EnhancedFileInfo::class); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php index 4b10617..539c2d4 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php @@ -86,10 +86,9 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings("PHPMD.ExcessiveMethodLength") - * * @return array> */ + // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength public function terminalCommandCompilationDataProvider(): array { $mockedEnhancedFileInfoExcluded1 = Mockery::mock(EnhancedFileInfo::class); diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php index c97b9ee..feded81 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php @@ -99,10 +99,9 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void /** * This data provider needs to be long because it contains all testing data. * - * @SuppressWarnings("PHPMD.ExcessiveMethodLength") - * * @return array> */ + // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength public function terminalCommandCompilationDataProvider(): array { $mockedEnhancedFileInfoExcluded1 = Mockery::mock(EnhancedFileInfo::class); From 6fd55d4dd1b4b512234d588bc918746f84223abe Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Thu, 27 Feb 2025 12:11:01 +0100 Subject: [PATCH 12/32] Too many methods and properties --- composer.json | 1 + config/phpcs/ZooRoyal/ruleset.xml | 1 + config/phpmd/phpmd.xml | 6 - .../Sniffs/ObjectCalisthenics/.dontSniffPHP | 0 .../Sniffs/ObjectCalisthenics/.dontStanPHP | 0 .../NonClassTypeTokenTypeException.php | 11 ++ .../ZooRoyal/Helper/ClassAnalyzer.php | 80 ++++++++++ .../ZooRoyal/Helper/NamingHelper.php | 54 +++++++ .../Metrics/MethodPerClassLimitSniff.php | 40 +++++ .../Metrics/PropertyPerClassLimitSniff.php | 39 +++++ .../MethodPerClassLimitSniffTest.php | 74 ++++++++++ .../MethodPerClassLimit/wrong/wrong.php.inc | 138 ++++++++++++++++++ .../MethodPerClassLimit/wrong/wrong2.php.inc | 137 +++++++++++++++++ .../MethodPerClassLimit/wrong/wrong3.php.inc | 138 ++++++++++++++++++ .../PropertyPerClassLimitSniffTest.php | 74 ++++++++++ .../correct/correct.php.inc | 14 ++ .../PropertyPerClassLimit/wrong/wrong.php.inc | 74 ++++++++++ .../ObjectsCallisthenics/FileFactory.php | 42 ++++++ .../ClassAnalyzerSource/SomeFile.php.inc | 21 +++ .../ZooRoyal/Helper/ClassAnalyzerTest.php | 43 ++++++ .../Helper/NamingSource/SomeFile.php.inc | 10 ++ .../Standards/ZooRoyal/Helper/NamingTest.php | 48 ++++++ .../PropertyHelperSource/SomeFile.php.inc | 12 ++ 23 files changed, 1051 insertions(+), 6 deletions(-) create mode 100644 src/main/php/Sniffs/ObjectCalisthenics/.dontSniffPHP create mode 100644 src/main/php/Sniffs/ObjectCalisthenics/.dontStanPHP create mode 100644 src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Exception/NonClassTypeTokenTypeException.php create mode 100644 src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/ClassAnalyzer.php create mode 100644 src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/NamingHelper.php create mode 100644 src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimitSniff.php create mode 100644 src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimitSniff.php create mode 100644 tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php create mode 100644 tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong.php.inc create mode 100644 tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong2.php.inc create mode 100644 tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong3.php.inc create mode 100644 tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimit/PropertyPerClassLimitSniffTest.php create mode 100644 tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimit/correct/correct.php.inc create mode 100644 tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimit/wrong/wrong.php.inc create mode 100644 tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php create mode 100644 tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/ClassAnalyzerSource/SomeFile.php.inc create mode 100644 tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/ClassAnalyzerTest.php create mode 100644 tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/NamingSource/SomeFile.php.inc create mode 100644 tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/NamingTest.php create mode 100644 tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/PropertyHelperSource/SomeFile.php.inc diff --git a/composer.json b/composer.json index b5f8577..ba99e5f 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,7 @@ "composer/semver": "^3.4", "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", "nette/neon": "^3.3", + "nette/utils": "^4.0", "nikic/php-parser": "^5.4.0", "php-di/php-di": "^7.0.1", "slevomat/coding-standard": "^8.10.0", diff --git a/config/phpcs/ZooRoyal/ruleset.xml b/config/phpcs/ZooRoyal/ruleset.xml index eec26a7..27a991f 100755 --- a/config/phpcs/ZooRoyal/ruleset.xml +++ b/config/phpcs/ZooRoyal/ruleset.xml @@ -13,6 +13,7 @@ + diff --git a/config/phpmd/phpmd.xml b/config/phpmd/phpmd.xml index 43909c1..2537612 100644 --- a/config/phpmd/phpmd.xml +++ b/config/phpmd/phpmd.xml @@ -9,12 +9,6 @@ - - - - - - diff --git a/src/main/php/Sniffs/ObjectCalisthenics/.dontSniffPHP b/src/main/php/Sniffs/ObjectCalisthenics/.dontSniffPHP new file mode 100644 index 0000000..e69de29 diff --git a/src/main/php/Sniffs/ObjectCalisthenics/.dontStanPHP b/src/main/php/Sniffs/ObjectCalisthenics/.dontStanPHP new file mode 100644 index 0000000..e69de29 diff --git a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Exception/NonClassTypeTokenTypeException.php b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Exception/NonClassTypeTokenTypeException.php new file mode 100644 index 0000000..57766e5 --- /dev/null +++ b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Exception/NonClassTypeTokenTypeException.php @@ -0,0 +1,11 @@ + + */ + private static array $propertyList = []; + + public static function getClassMethodCount(File $file, int $position): int + { + self::ensureIsClassTraitOrInterface($file, $position); + + $methodCount = 0; + $pointer = $position; + + while (($next = $file->findNext(T_FUNCTION, $pointer + 1)) !== false) { + ++$methodCount; + + $pointer = $next; + } + + return $methodCount; + } + + public static function getClassPropertiesCount(File $file, int $position): int + { + return count(self::getClassProperties($file, $position)); + } + + /** + * @return array + */ + public static function getClassProperties(File $file, int $position): array + { + $tokens = $file->getTokens(); + $token = $tokens[$position]; + $pointer = $token['scope_opener']; + + self::$propertyList = []; + + while (($pointer = $file->findNext(T_VARIABLE, ($pointer + 1), $token['scope_closer'])) !== false) { + self::extractPropertyIfFound($file, (int) $pointer); + } + + return self::$propertyList; + } + + private static function extractPropertyIfFound(File $file, int $position): void + { + if (PropertyHelper::isProperty($file, $position)) { + self::$propertyList[] = $position; + } + } + + private static function ensureIsClassTraitOrInterface(File $file, int $position): void + { + $token = $file->getTokens()[$position]; + + self::ensureIsClassLikeToken($token); + } + + private static function ensureIsClassLikeToken(array $token): void + { + if (in_array($token['code'], [T_CLASS, T_INTERFACE, T_TRAIT], true)) { + return; + } + + $message = sprintf('Must be class, interface or trait. "%s" given.', ltrim($token['type'], 'T_')); + throw new NonClassTypeTokenTypeException($message); + } +} diff --git a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/NamingHelper.php b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/NamingHelper.php new file mode 100644 index 0000000..64e7ce0 --- /dev/null +++ b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/NamingHelper.php @@ -0,0 +1,54 @@ + + */ + private const CODE_TO_TYPE_NAME_MAP = [ + T_CONST => 'Constant', + T_CLASS => 'Class', + T_FUNCTION => 'Function', + T_TRAIT => 'Trait', + T_INTERFACE => 'Interface', + ]; + + public static function getTypeName(File $file, int $position): string + { + $token = $file->getTokens()[$position]; + $tokenCode = $token['code']; + if (isset(self::CODE_TO_TYPE_NAME_MAP[$tokenCode])) { + return self::CODE_TO_TYPE_NAME_MAP[$tokenCode]; + } + + if ($token['code'] === T_VARIABLE) { + if (PropertyHelper::isProperty($file, $position)) { + return 'Property'; + } + + return 'Variable'; + } + + return ''; + } + + public static function getElementName(File $file, int $position): string + { + $name = $file->getTokens()[$position]['content']; + + if (Strings::startsWith($name, '$')) { + return trim($name, '$'); + } + + $namePosition = $file->findNext(T_STRING, $position, $position + 3); + + return $file->getTokens()[$namePosition]['content']; + } +} diff --git a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimitSniff.php b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimitSniff.php new file mode 100644 index 0000000..222357f --- /dev/null +++ b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimitSniff.php @@ -0,0 +1,40 @@ + + */ + public function register(): array + { + return [T_CLASS, T_INTERFACE, T_TRAIT]; + } + + public function process(File $file, $position) + { + $methodCount = ClassAnalyzer::getClassMethodCount($file, $position); + + if ($methodCount > $this->maxCount) { + $typeName = NamingHelper::getTypeName($file, $position); + $message = sprintf(self::ERROR_MESSAGE, $typeName, $methodCount, $this->maxCount); + + $file->addError($message, $position, 'MethodPerClassLimit'); + } + } +} diff --git a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimitSniff.php b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimitSniff.php new file mode 100644 index 0000000..90d8514 --- /dev/null +++ b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimitSniff.php @@ -0,0 +1,39 @@ + + */ + public function register(): array + { + return [T_CLASS, T_TRAIT]; + } + + public function process(File $file, $position) + { + $propertiesCount = ClassAnalyzer::getClassPropertiesCount($file, $position); + + if ($propertiesCount > $this->maxCount) { + $tokenType = $file->getTokens()[$position]['content']; + + $message = sprintf(self::ERROR_MESSAGE, $tokenType, $propertiesCount, $this->maxCount); + $file->addError($message, $position, 'PropertyPerClassLimit'); + } + } +} diff --git a/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php new file mode 100644 index 0000000..1082cf5 --- /dev/null +++ b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php @@ -0,0 +1,74 @@ + */ + private array $commandPrefix; + + #[Override] + public static function setUpBeforeClass(): void + { + parent::setUpBeforeClass(); + $reflection = new ReflectionClass(ClassLoader::class); + self::$vendorDir = dirname($reflection->getFileName(), 2); + + require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php'; + } + + #[Override] + protected function setUp(): void + { + $this->commandPrefix = [ + 'vendor/bin/phpcs', + '--sniffs=' . self::SNIFF_NAME, + '--standard=ZooRoyal', + '-s', + ]; + } + + /** + * @test + * @medium + * @covers \Zooroyal\CodingStandard\Sniffs\ObjectCalisthenics\Standards\ZooRoyal\Sniffs\Metrics\MethodPerClassLimitSniff + */ + public function itShouldReportNoErrors(): void + { + $this->commandPrefix[] = __FILE__; + $subject = new Process($this->commandPrefix, self::$vendorDir . '/../'); + $subject->mustRun(); + $subject->wait(); + self::assertSame(0, $subject->getExitCode()); + } + + /** + * @test + * @medium + * @covers \Zooroyal\CodingStandard\Sniffs\ObjectCalisthenics\Standards\ZooRoyal\Sniffs\Metrics\MethodPerClassLimitSniff + */ + public function itShouldReportErrorsForExistingMixedTypes(): void + { + $this->commandPrefix[] = self::FIXTURE_DIRECTORY; + $subject = new Process($this->commandPrefix, self::$vendorDir . '/../'); + $subject->run(); + $subject->wait(); + $output = $subject->getOutput(); + self::assertMatchesRegularExpression('/Trait has too many methods: 26\. Can be up to 25 methods\./', $output); + self::assertMatchesRegularExpression('/Class has too many methods: 26\. Can be up to 25 methods\./', $output); + self::assertMatchesRegularExpression('/Interface has too many methods: 26\. Can be up to 25 methods\./', $output); + } +} diff --git a/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong.php.inc b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong.php.inc new file mode 100644 index 0000000..1462670 --- /dev/null +++ b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong.php.inc @@ -0,0 +1,138 @@ + */ + private array $commandPrefix; + + #[Override] + public static function setUpBeforeClass(): void + { + parent::setUpBeforeClass(); + $reflection = new ReflectionClass(ClassLoader::class); + self::$vendorDir = dirname($reflection->getFileName(), 2); + + require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php'; + } + + #[Override] + protected function setUp(): void + { + $this->commandPrefix = [ + 'vendor/bin/phpcs', + '--sniffs=' . self::SNIFF_NAME, + '--standard=ZooRoyal', + '-s', + ]; + } + + /** + * @test + * @medium + */ + public function itShouldReportNoErrors(): void + { + $this->commandPrefix[] = self::FIXTURE_DIRECTORY_CORRECT; + $subject = new Process($this->commandPrefix, self::$vendorDir . '/../'); + $subject->mustRun(); + $subject->wait(); + self::assertSame(0, $subject->getExitCode()); + } + + /** + * @test + * @medium + */ + public function itShouldReportErrorsForExistingMixedTypes(): void + { + $this->commandPrefix[] = self::FIXTURE_DIRECTORY_WRONG; + $subject = new Process($this->commandPrefix, self::$vendorDir . '/../'); + $subject->run(); + $subject->wait(); + $output = $subject->getOutput(); + self::assertMatchesRegularExpression('/"class" has too many properties: 26\. Can be up to 25/', $output); + } +} diff --git a/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimit/correct/correct.php.inc b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimit/correct/correct.php.inc new file mode 100644 index 0000000..50d10ae --- /dev/null +++ b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimit/correct/correct.php.inc @@ -0,0 +1,14 @@ +setContent($fileContent); + $file->parse(); + + return $file; + } +} diff --git a/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/ClassAnalyzerSource/SomeFile.php.inc b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/ClassAnalyzerSource/SomeFile.php.inc new file mode 100644 index 0000000..a290b2d --- /dev/null +++ b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/ClassAnalyzerSource/SomeFile.php.inc @@ -0,0 +1,21 @@ +file = $fileFactory->createFile(__DIR__ . '/ClassAnalyzerSource/SomeFile.php.inc'); + } + + public function testMethodCount(): void + { + $this->assertSame(2, ClassAnalyzer::getClassMethodCount($this->file, self::CLASS_POSITION)); + } + + public function testProperties(): void + { + $properties = ClassAnalyzer::getClassProperties($this->file, self::CLASS_POSITION); + + $this->assertCount(1, $properties); + } + + public function testPropertyCount(): void + { + $this->assertSame(1, ClassAnalyzer::getClassPropertiesCount($this->file, self::CLASS_POSITION)); + } +} diff --git a/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/NamingSource/SomeFile.php.inc b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/NamingSource/SomeFile.php.inc new file mode 100644 index 0000000..8dfbd03 --- /dev/null +++ b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/NamingSource/SomeFile.php.inc @@ -0,0 +1,10 @@ +fileFactory = new FileFactory(); + } + + public function test(): void + { + $file = $this->fileFactory->createFile(__DIR__ . '/NamingSource/SomeFile.php.inc'); + + $name = NamingHelper::getElementName($file, self::CLASS_POSITION); + $this->assertSame('SomeClass', $name); + + $name = NamingHelper::getElementName($file, self::CONSTANT_POSITION); + $this->assertSame('SOME_CONSTANT', $name); + + $name = NamingHelper::getElementName($file, self::PROPERTY_POSITION); + $this->assertSame('someProperty', $name); + } +} diff --git a/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/PropertyHelperSource/SomeFile.php.inc b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/PropertyHelperSource/SomeFile.php.inc new file mode 100644 index 0000000..c2046d9 --- /dev/null +++ b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/PropertyHelperSource/SomeFile.php.inc @@ -0,0 +1,12 @@ +assignment = $argument; + $variable = 5; + } +} From a6ae99b84bcf6ed564f69369718b16920a1b4d98 Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Tue, 18 Mar 2025 17:46:46 +0100 Subject: [PATCH 13/32] More PHPMD replacements --- composer.json | 2 +- config/phpcs/ZooRoyal/ruleset.xml | 3 +- config/phpmd/phpmd.xml | 18 +- .../ZooRoyal/Helper/ClassAnalyzer.php | 4 +- .../ZooRoyal/Helper/NamingHelper.php | 1 + .../Sniffs/Naming/NameLengthSniff.php | 72 ++++++ .../Safe/CheckSafeFunctionUsageSniff.php | 4 +- .../MethodPerClassLimitSniffTest.php | 3 +- .../PropertyPerClassLimitSniffTest.php | 4 +- .../Sniffs/Naming/NameLengthSniffTest.php | 234 ++++++++++++++++++ 10 files changed, 327 insertions(+), 18 deletions(-) create mode 100644 src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniff.php create mode 100644 tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniffTest.php diff --git a/composer.json b/composer.json index ba99e5f..99d9e1b 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "amphp/process": "^v1.1.4", "brianium/paratest": "^v6.11.1", "infection/infection": ">=0.29.12", - "mockery/mockery": "^1.6.12", + "mockery/mockery": "1.6.11", "phpunit/phpunit": "^9.6.16", "roave/security-advisories": "dev-latest", "sebastianknott/hamcrest-object-accessor": "^3.0.0" diff --git a/config/phpcs/ZooRoyal/ruleset.xml b/config/phpcs/ZooRoyal/ruleset.xml index 27a991f..d97e5c5 100755 --- a/config/phpcs/ZooRoyal/ruleset.xml +++ b/config/phpcs/ZooRoyal/ruleset.xml @@ -78,11 +78,12 @@ + diff --git a/config/phpmd/phpmd.xml b/config/phpmd/phpmd.xml index 2537612..59a7ba7 100644 --- a/config/phpmd/phpmd.xml +++ b/config/phpmd/phpmd.xml @@ -8,16 +8,9 @@ - - - - - - - @@ -30,8 +23,17 @@ - + + + + + + + + + + diff --git a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/ClassAnalyzer.php b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/ClassAnalyzer.php index 8179fae..c49aad2 100644 --- a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/ClassAnalyzer.php +++ b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/ClassAnalyzer.php @@ -10,9 +10,7 @@ final class ClassAnalyzer { - /** - * @var array - */ + /** @var array */ private static array $propertyList = []; public static function getClassMethodCount(File $file, int $position): int diff --git a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/NamingHelper.php b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/NamingHelper.php index 64e7ce0..51c174a 100644 --- a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/NamingHelper.php +++ b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/NamingHelper.php @@ -6,6 +6,7 @@ use Nette\Utils\Strings; use PHP_CodeSniffer\Files\File; +use SlevomatCodingStandard\Helpers\PropertyHelper; final class NamingHelper { diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniff.php new file mode 100644 index 0000000..7408db0 --- /dev/null +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniff.php @@ -0,0 +1,72 @@ +getTokens(); + $token = $tokens[$stackPtr]['content']; + + $name = match ($token) { + 'function' => FunctionHelper::getName($phpcsFile, $stackPtr), + 'class', 'trait', 'interface' => ClassHelper::getName($phpcsFile, $stackPtr), + default => $this->getName($tokens[$stackPtr]['content']), + }; + + if (strlen($name) > $this->maximumLength) { + $error = 'Name "%s" is greater than %s characters long'; + $data = [$name, $this->maximumLength]; + $phpcsFile->addError($error, $stackPtr, 'NameTooLong', $data); + } + + if (strlen($name) < $this->minimumLength) { + $error = 'Name "%s" is less than %s characters long'; + $data = [$name, $this->minimumLength]; + $phpcsFile->addError($error, $stackPtr, 'NameTooShort', $data); + } + } + + + private function getName(string $content): string + { + // Add exclusion for variable $i so you cant use it in for loops. + if ($content === '$i') { + return str_pad($content, $this->maximumLength, 'i'); + } + + return ltrim($content, '$'); + } +} diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php index 76595e3..feaad45 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php @@ -68,7 +68,7 @@ public function __construct() /** * Description is in the inherited doc. * - * @{inheritDoc} + * {@inheritDoc} * * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification We must * stay compatible with the interface even if we don't like it. @@ -84,7 +84,7 @@ public function register(): array /** * Description is in the inherited doc. * - * @{inheritDoc} + * {@inheritDoc} * * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint We must * stay compatible with the interface even if we don't like it. diff --git a/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php index 1082cf5..6509feb 100644 --- a/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php +++ b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php @@ -1,5 +1,7 @@ subject = new NameLengthSniff(); + } + + /** + * @test + * @dataProvider processHappyPathDataProvider + */ + public function processHappyPath(string $name): void + { + $mockedFile = mock(File::class); + $forgedStackPointer = 0; + $forgedTokens = [ $forgedStackPointer => ['content' => $name]]; + + $mockedFile->expects()->getTokens()->andReturn($forgedTokens); + $mockedFile->shouldNotReceive('addError'); + + $this->subject->process($mockedFile, $forgedStackPointer); + } + + /** @return array> */ + public function processHappyPathDataProvider(): array + { + return [ + 'Good Name' => ['name' => 'aaaaaaa'], + 'i' => ['name' => 'i'], + ]; + } + + + /** + * @test + * @runInSeparateProcess + * @preserveGlobalState false + * @dataProvider processReportsErrorIfClassysAreBadDataProvider + */ + public function processReportsErrorIfClassysAreBad( + string $token, + string $name, + string $errorMessage, + string $code, + int $length, + ): void { + $mockedFile = mock(File::class); + $mockedClassHelper = mock('overload:' . ClassHelper::class); + + $forgedStackPointer = 0; + $forgedTokens = [ $forgedStackPointer => ['content' => $token]]; + + $mockedFile->expects()->getTokens()->andReturn($forgedTokens); + $mockedClassHelper->expects()->getName($mockedFile, $forgedStackPointer)->andReturn($name); + + $mockedFile->expects()->addError( + $errorMessage, + $forgedStackPointer, + $code, + [$name, $length] + ); + + $this->subject->process($mockedFile, $forgedStackPointer); + } + + + /** @return array> */ + // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength + public function processReportsErrorIfClassysAreBadDataProvider(): array + { + return [ + 'class too short' => [ + 'token' => 'class', + 'name' => '$a', + 'errorMessage' => 'Name "%s" is less than %s characters long', + 'code' => 'NameTooShort', + 'length' => 3, + ], + 'class too long' => [ + 'token' => 'class', + 'name' => str_pad('$', 71, 'a'), + 'errorMessage' => 'Name "%s" is greater than %s characters long', + 'code' => 'NameTooLong', + 'length' => 60, + ], + 'trait too short' => [ + 'token' => 'trait', + 'name' => '$a', + 'errorMessage' => 'Name "%s" is less than %s characters long', + 'code' => 'NameTooShort', + 'length' => 3, + ], + 'trait too long' => [ + 'token' => 'trait', + 'name' => str_pad('$', 71, 'a'), + 'errorMessage' => 'Name "%s" is greater than %s characters long', + 'code' => 'NameTooLong', + 'length' => 60, + ], + 'interface too short' => [ + 'token' => 'interface', + 'name' => '$a', + 'errorMessage' => 'Name "%s" is less than %s characters long', + 'code' => 'NameTooShort', + 'length' => 3, + ], + 'interface too long' => [ + 'token' => 'interface', + 'name' => str_pad('$', 71, 'a'), + 'errorMessage' => 'Name "%s" is greater than %s characters long', + 'code' => 'NameTooLong', + 'length' => 60, + ], + ]; + } + + /** + * @test + * @runInSeparateProcess + * @preserveGlobalState false + * @dataProvider processReportsErrorIfFunctionIsBadDataProvider + */ + public function processReportsErrorIfFunctionIsBad( + string $functionName, + string $errorMessage, + string $code, + int $length, + ): void { + $mockedFile = Mockery::mock(File::class); + $mockedFunctionHelper = mock('overload:' . FunctionHelper::class); + + $forgedStackPointer = 0; + $forgedTokens = [ $forgedStackPointer => ['content' => 'function']]; + + $mockedFile->expects()->getTokens()->andReturn($forgedTokens); + $mockedFunctionHelper->expects()->getName($mockedFile, $forgedStackPointer)->andReturn($functionName); + $mockedFile->expects()->addError( + $errorMessage, + $forgedStackPointer, + $code, + [$functionName, $length] + ); + + $this->subject->process($mockedFile, $forgedStackPointer); + } + + /** @return array> */ + public function processReportsErrorIfFunctionIsBadDataProvider(): array + { + return [ + 'too short' => [ + 'functionName' => 'a', + 'errorMessage' => 'Name "%s" is less than %s characters long', + 'code' => 'NameTooShort', + 'length' => 3, + ], + 'too long' => [ + 'functionName' => str_pad('a', 71, 'a'), + 'errorMessage' => 'Name "%s" is greater than %s characters long', + 'code' => 'NameTooLong', + 'length' => 60, + ], + ]; + } + + /** + * @test + * + * @dataProvider processReportsErrorIfVariableIsBadDataProvider + */ + public function processReportsErrorIfVariableIsBad( + string $variable, + string $errorMessage, + string $code, + int $length, + ): void { + $mockedFile = mock(File::class); + $forgedStackPointer = 0; + $forgedTokens = [ $forgedStackPointer => ['content' => $variable]]; + + $mockedFile->expects()->getTokens()->andReturn($forgedTokens); + $mockedFile->expects()->addError( + $errorMessage, + $forgedStackPointer, + $code, + [ltrim($variable, '$'), $length] + ); + + $this->subject->process($mockedFile, $forgedStackPointer); + } + + /** @return array> */ + public function processReportsErrorIfVariableIsBadDataProvider(): array + { + return [ + 'too short' => [ + 'variable' => '$a', + 'errorMessage' => 'Name "%s" is less than %s characters long', + 'code' => 'NameTooShort', + 'length' => 3, + ], + 'too long' => [ + 'variable' => str_pad('$', 71, 'a'), + 'errorMessage' => 'Name "%s" is greater than %s characters long', + 'code' => 'NameTooLong', + 'length' => 60, + ], + ]; + } + + /** + * @test + */ + public function registerReturnsExpectedTokens(): void + { + $expected = [T_VARIABLE, T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT, T_PROPERTY]; + $this->assertEquals($expected, $this->subject->register()); + } +} From be639b094e7ac0c953abcd9c6dede1821c6fa4b9 Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Thu, 20 Mar 2025 17:09:00 +0100 Subject: [PATCH 14/32] code style - phpmd removal WIP --- config/phpmd/phpmd.xml | 25 +--------- .../Metrics/ObjectCouplingLimitSniff.php | 41 +++++++++++++++++ .../Metrics/ParameterPerMethodLimitSniff.php | 46 +++++++++++++++++++ 3 files changed, 88 insertions(+), 24 deletions(-) create mode 100644 src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php create mode 100644 src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ParameterPerMethodLimitSniff.php diff --git a/config/phpmd/phpmd.xml b/config/phpmd/phpmd.xml index 59a7ba7..1b9f653 100644 --- a/config/phpmd/phpmd.xml +++ b/config/phpmd/phpmd.xml @@ -7,33 +7,10 @@ ZooRoyal Ruleset for PHP MessDetector - - - - - - - - - - - - - - - - - - + - - - - - - diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php new file mode 100644 index 0000000..85b313a --- /dev/null +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php @@ -0,0 +1,41 @@ + + */ + public function register(): array + { + return [T_CLASS, T_INTERFACE, T_TRAIT]; + } + + public function process(File $file, $position): void + { + $usesCount = 0; + $pointer = 0; + $className = $file->getTokens()[$file->findNext(T_STRING, $position)]['content']; + while (($next = $file->findNext(T_USE, $pointer + 1)) !== false) { + $usesCount++; + $pointer = $next; + } + if ($usesCount > $this->maxCount) { + $message = sprintf(self::ERROR_MESSAGE, $className, $usesCount, $this->maxCount + 1); + $file->addError($message, $position, 'ParameterPerMethodLimit'); + } + } +} diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ParameterPerMethodLimitSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ParameterPerMethodLimitSniff.php new file mode 100644 index 0000000..d80af8e --- /dev/null +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ParameterPerMethodLimitSniff.php @@ -0,0 +1,46 @@ + */ + public function register(): array + { + return [T_FUNCTION]; + } + + /** @param int $position */ + public function process(File $file, $position): void + { + $parameterCount = $this->getParameterCount($file, $position); + $methodName = $file->getTokens()[$file->findNext(T_STRING, $position)]['content']; + if ($parameterCount > $this->maxCount) { + $message = sprintf(self::ERROR_MESSAGE, $methodName, $parameterCount, $this->maxCount); + $file->addError($message, $position, 'ParameterPerMethodLimit'); + } + } + + private function getParameterCount(File $file, int $position): int + { + $count = 0; + $tokens = $file->getTokens(); + $token = $tokens[$position]; + $pointer = $token['parenthesis_closer']; + for ($i = $position; $i < $pointer; $i++) { + if ($tokens[$i]['code'] === T_VARIABLE) { + $count++; + } + } + return $count; + } +} From 674e15eeb43d66122ecbae4efb1e8bb88bf11212 Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Fri, 21 Mar 2025 11:43:42 +0100 Subject: [PATCH 15/32] code style - phpmd removal WIP --- config/phpmd/phpmd.xml | 2 -- .../ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/config/phpmd/phpmd.xml b/config/phpmd/phpmd.xml index 1b9f653..8d18d96 100644 --- a/config/phpmd/phpmd.xml +++ b/config/phpmd/phpmd.xml @@ -7,8 +7,6 @@ ZooRoyal Ruleset for PHP MessDetector - - diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php index 85b313a..dedc73a 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php @@ -28,12 +28,12 @@ public function process(File $file, $position): void { $usesCount = 0; $pointer = 0; - $className = $file->getTokens()[$file->findNext(T_STRING, $position)]['content']; while (($next = $file->findNext(T_USE, $pointer + 1)) !== false) { $usesCount++; $pointer = $next; } if ($usesCount > $this->maxCount) { + $className = $file->getTokens()[$file->findNext(T_STRING, $position)]['content']; $message = sprintf(self::ERROR_MESSAGE, $className, $usesCount, $this->maxCount + 1); $file->addError($message, $position, 'ParameterPerMethodLimit'); } From 07ef81de1d3a1b25323f28440fcf6d727ed7a5b6 Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Fri, 21 Mar 2025 11:47:16 +0100 Subject: [PATCH 16/32] code style - phpmd removal WIP --- .../Metrics/ObjectCouplingLimitSniff.php | 21 ++++++++++++++----- .../Metrics/ParameterPerMethodLimitSniff.php | 18 ++++++++++++++-- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php index dedc73a..2897b68 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php @@ -9,21 +9,32 @@ final class ObjectCouplingLimitSniff implements Sniff { - /** - * @var string - */ - private const string ERROR_MESSAGE = 'The class %s has a coupling between objects value of %s. Consider to reduce the number of dependencies under %s.'; + private const string ERROR_MESSAGE = + 'The class %s has a coupling between objects value of %s. Consider to reduce the number of dependencies under %s.'; public int $maxCount = 15; /** - * @return array + * Description is in the inherited doc. + * + * {@inheritDoc} + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint We must + * stay compatible with the interface even if we don't like it. */ public function register(): array { return [T_CLASS, T_INTERFACE, T_TRAIT]; } + /** + * Description is in the inherited doc. + * + * {@inheritDoc} + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint We must + * stay compatible with the interface even if we don't like it. + */ public function process(File $file, $position): void { $usesCount = 0; diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ParameterPerMethodLimitSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ParameterPerMethodLimitSniff.php index d80af8e..8831086 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ParameterPerMethodLimitSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ParameterPerMethodLimitSniff.php @@ -13,13 +13,27 @@ final class ParameterPerMethodLimitSniff implements Sniff public int $maxCount = 10; - /** @return array */ + /** + * Description is in the inherited doc. + * + * {@inheritDoc} + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint We must + * stay compatible with the interface even if we don't like it. + */ public function register(): array { return [T_FUNCTION]; } - /** @param int $position */ + /** + * Description is in the inherited doc. + * + * {@inheritDoc} + * + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint We must + * stay compatible with the interface even if we don't like it. + */ public function process(File $file, $position): void { $parameterCount = $this->getParameterCount($file, $position); From 3772eb443c97d565a6d0baaae427a10e1894e4e9 Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Fri, 21 Mar 2025 11:55:49 +0100 Subject: [PATCH 17/32] code style - fixes --- .../ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php | 6 +++--- .../MethodPerClassLimit/MethodPerClassLimitSniffTest.php | 3 ++- .../PropertyPerClassLimitSniffTest.php | 4 ++-- .../Generic/TerminalCommand/Target/TargetDecoratorTest.php | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php index 2897b68..3782427 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php @@ -9,8 +9,8 @@ final class ObjectCouplingLimitSniff implements Sniff { - private const string ERROR_MESSAGE = - 'The class %s has a coupling between objects value of %s. Consider to reduce the number of dependencies under %s.'; + private const string ERROR_MESSAGE + = 'The class %s has a coupling between objects value of %s. Consider to reduce the number of dependencies under %s.'; public int $maxCount = 15; @@ -46,7 +46,7 @@ public function process(File $file, $position): void if ($usesCount > $this->maxCount) { $className = $file->getTokens()[$file->findNext(T_STRING, $position)]['content']; $message = sprintf(self::ERROR_MESSAGE, $className, $usesCount, $this->maxCount + 1); - $file->addError($message, $position, 'ParameterPerMethodLimit'); + $file->addError($message, $position, 'ObjectCouplingLimit'); } } } diff --git a/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php index 6509feb..d8f42da 100644 --- a/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php +++ b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php @@ -1,8 +1,9 @@ Date: Fri, 21 Mar 2025 14:46:51 +0100 Subject: [PATCH 18/32] code style - fixes --- .../ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php | 5 +++++ .../MethodPerClassLimit/MethodPerClassLimitSniffTest.php | 1 + .../PropertyPerClassLimitSniffTest.php | 2 ++ .../CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php | 2 +- .../StaticCodeAnalysis/FindFilesToCheckCommandTest.php | 2 +- .../Generic/TerminalCommand/Target/TargetDecoratorTest.php | 6 +++--- tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php | 2 ++ 7 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php index 3782427..bd159a6 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php @@ -38,7 +38,12 @@ public function register(): array public function process(File $file, $position): void { $usesCount = 0; + $tokens = $file->getTokens(); $pointer = 0; + while (($next = $file->findNext(T_COMMENT, $pointer + 1)) !== false) { + var_dump($tokens[$next]); + $pointer = $next; + } while (($next = $file->findNext(T_USE, $pointer + 1)) !== false) { $usesCount++; $pointer = $next; diff --git a/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php index d8f42da..37eec1b 100644 --- a/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php +++ b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php @@ -1,6 +1,7 @@ Date: Fri, 21 Mar 2025 14:49:30 +0100 Subject: [PATCH 19/32] remove debug output --- .../ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php index bd159a6..480c528 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php @@ -40,16 +40,12 @@ public function process(File $file, $position): void $usesCount = 0; $tokens = $file->getTokens(); $pointer = 0; - while (($next = $file->findNext(T_COMMENT, $pointer + 1)) !== false) { - var_dump($tokens[$next]); - $pointer = $next; - } while (($next = $file->findNext(T_USE, $pointer + 1)) !== false) { $usesCount++; $pointer = $next; } if ($usesCount > $this->maxCount) { - $className = $file->getTokens()[$file->findNext(T_STRING, $position)]['content']; + $className = $tokens[$file->findNext(T_STRING, $position)]['content']; $message = sprintf(self::ERROR_MESSAGE, $className, $usesCount, $this->maxCount + 1); $file->addError($message, $position, 'ObjectCouplingLimit'); } From 86a2f5f9ced248b25bcfa9521b642096f982c594 Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Fri, 21 Mar 2025 16:05:42 +0100 Subject: [PATCH 20/32] added annotations where needed --- .../JSESLint/TerminalCommand.php | 1 + .../JSStyleLint/TerminalCommand.php | 1 + .../PHPCodeSniffer/TerminalCommand.php | 1 + .../PHPCopyPasteDetector/TerminalCommand.php | 1 + .../PHPMessDetector/TerminalCommand.php | 1 + .../PHPParallelLint/TerminalCommand.php | 1 + .../PHPStan/TerminalCommand.php | 1 + .../Metrics/ObjectCouplingLimitSniff.php | 6 ++++++ .../ApplicationFactoryTest.php | 5 +++++ .../EventDispatcherFactoryTest.php | 5 +++++ .../AllToolsCommandTest.php | 2 +- .../FindFilesToCheckCommandTest.php | 2 +- .../Target/TargetDecoratorTest.php | 2 +- .../ObjectsCallisthenics/FileFactory.php | 2 +- .../ZooRoyal/Helper/ClassAnalyzerTest.php | 5 +---- .../Standards/ZooRoyal/Helper/NamingTest.php | 19 +++++-------------- 16 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php index dbfb99a..f185baa 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php @@ -20,6 +20,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTrait; +/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ class TerminalCommand extends AbstractTerminalCommand implements FixTerminalCommand, TargetTerminalCommand, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php index 680ee73..89e8975 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php @@ -20,6 +20,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTrait; +/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ class TerminalCommand extends AbstractTerminalCommand implements TargetTerminalCommand, FixTerminalCommand, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php index 23c00e8..3693882 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php @@ -26,6 +26,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTrait; +/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ class TerminalCommand extends AbstractTerminalCommand implements FixTerminalCommand, TargetTerminalCommand, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php index 3f3671b..ab9c84b 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php @@ -16,6 +16,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTrait; +/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ class TerminalCommand extends AbstractTerminalCommand implements ExclusionTerminalCommand, FileExtensionTerminalCommand, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php index e1a18fb..6cd2a1f 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php @@ -15,6 +15,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTrait; +/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ class TerminalCommand extends AbstractTerminalCommand implements TargetTerminalCommand, FileExtensionTerminalCommand, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php index ad0f562..02d2d65 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php @@ -17,6 +17,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTrait; +/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ class TerminalCommand extends AbstractTerminalCommand implements TargetTerminalCommand, ExclusionTerminalCommand, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php index ad8a4a5..a5c32cc 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php @@ -16,6 +16,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTrait; +/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ class TerminalCommand extends AbstractTerminalCommand implements TargetTerminalCommand, VerboseTerminalCommand, diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php index 480c528..478c9ed 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php @@ -6,11 +6,13 @@ use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; +use SlevomatCodingStandard\Helpers\SuppressHelper; final class ObjectCouplingLimitSniff implements Sniff { private const string ERROR_MESSAGE = 'The class %s has a coupling between objects value of %s. Consider to reduce the number of dependencies under %s.'; + private const string NAME = 'ZooRoyal.Metrics.ObjectCouplingLimit'; public int $maxCount = 15; @@ -37,6 +39,10 @@ public function register(): array */ public function process(File $file, $position): void { + if (SuppressHelper::isSniffSuppressed($file, $position, self::NAME)) { + return; + } + $usesCount = 0; $tokens = $file->getTokens(); $pointer = 0; diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php index 1b199ac..3d5f450 100644 --- a/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php +++ b/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php @@ -25,6 +25,11 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPStan\PHPStanCommand; use Zooroyal\CodingStandard\Tests\Tools\SubjectFactory; +/** + * Class ApplicationFactoryTest + * + * @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit + */ class ApplicationFactoryTest extends TestCase { private ApplicationFactory $subject; diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php index 4b195a2..a571d27 100644 --- a/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php +++ b/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php @@ -23,6 +23,11 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseDecorator; use Zooroyal\CodingStandard\Tests\Tools\SubjectFactory; +/** + * Class EventDispatcherFactoryTest + * + * @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit + */ class EventDispatcherFactoryTest extends TestCase { private EventDispatcherFactory $subject; diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php index 1fe184e..206c09c 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php @@ -25,7 +25,7 @@ /** * Class AllToolsCommandTest * - * @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit.ObjectCouplingLimit + * @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ class AllToolsCommandTest extends TestCase { diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php index 957bdda..127cdc2 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php @@ -25,7 +25,7 @@ /** * Class FindFilesToCheckCommandTest * - * @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit.ObjectCouplingLimit + * @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ class FindFilesToCheckCommandTest extends TestCase { diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php index 558cca4..27f8135 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php @@ -25,7 +25,7 @@ /** * This is a very busy test and needs all the objects ;/ * - * @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit.ObjectCouplingLimit + * @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ class TargetDecoratorTest extends TestCase { diff --git a/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php b/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php index 707db62..793c538 100644 --- a/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php +++ b/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php @@ -10,7 +10,7 @@ use PHP_CodeSniffer\Ruleset; use PHP_CodeSniffer\Util\Tokens; -use function \Safe\define; +use function Safe\define; final class FileFactory { diff --git a/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/ClassAnalyzerTest.php b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/ClassAnalyzerTest.php index 989aee1..e8ba26b 100644 --- a/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/ClassAnalyzerTest.php +++ b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/ClassAnalyzerTest.php @@ -11,10 +11,7 @@ final class ClassAnalyzerTest extends TestCase { - /** - * @var int - */ - private const CLASS_POSITION = 3; + private const int CLASS_POSITION = 3; private File $file; diff --git a/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/NamingTest.php b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/NamingTest.php index 10aba89..491266f 100644 --- a/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/NamingTest.php +++ b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/NamingTest.php @@ -10,20 +10,11 @@ final class NamingTest extends TestCase { - /** - * @var int - */ - private const CLASS_POSITION = 4; - - /** - * @var int - */ - private const CONSTANT_POSITION = 12; - - /** - * @var int - */ - private const PROPERTY_POSITION = 25; + private const int CLASS_POSITION = 4; + + private const int CONSTANT_POSITION = 12; + + private const int PROPERTY_POSITION = 25; private FileFactory $fileFactory; From 19f4f8b22186d6697b2a254e2eff9497b5f867cb Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Mon, 24 Mar 2025 09:15:01 +0100 Subject: [PATCH 21/32] modify autoload trigger for Tokens Class --- tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php b/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php index 793c538..b8698da 100644 --- a/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php +++ b/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php @@ -25,7 +25,7 @@ public function __construct() // initialize Token constants if (! defined('T_NONE')) { - new Tokens(); + define('_TOKENS_LOADED_FROM_CLASS', Tokens::class); //trigger autoload of Tokens class } } From fcd7b84c88dfe386df85c4ae6183086a0cdba048 Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Mon, 24 Mar 2025 09:17:09 +0100 Subject: [PATCH 22/32] modify autoload trigger for Tokens Class --- tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php b/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php index b8698da..8a2c237 100644 --- a/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php +++ b/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php @@ -25,7 +25,8 @@ public function __construct() // initialize Token constants if (! defined('T_NONE')) { - define('_TOKENS_LOADED_FROM_CLASS', Tokens::class); //trigger autoload of Tokens class + //trigger autoload of Tokens class + define('_TOKENS_LOADED_FROM_CLASS', Tokens::class); } } From 76c3092cfb2c0bdd5a91e9ebf7bef65a7f0f4289 Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Tue, 25 Mar 2025 09:00:13 +0100 Subject: [PATCH 23/32] switch to implementation from branch 8.4-variant --- config/phpcs/ZooRoyal/ruleset.xml | 4 +- .../JSESLint/TerminalCommand.php | 2 +- .../JSStyleLint/TerminalCommand.php | 2 +- .../PHPCodeSniffer/TerminalCommand.php | 2 +- .../PHPCopyPasteDetector/TerminalCommand.php | 2 +- .../PHPMessDetector/TerminalCommand.php | 2 +- .../PHPParallelLint/TerminalCommand.php | 2 +- .../PHPStan/TerminalCommand.php | 2 +- .../Metrics/ObjectCouplingLimitSniff.php | 59 ----------- .../Metrics/ParameterPerMethodLimitSniff.php | 60 ------------ .../TypeHints/LimitFunctionArgumentSniff.php | 39 ++++++++ .../TypeHints/LimitUseStatementSniff.php | 50 ++++++++++ .../FileSearch/FastCachedFileSearchTest.php | 3 + .../ApplicationFactoryTest.php | 3 +- .../EventDispatcherFactoryTest.php | 3 +- .../AllToolsCommandTest.php | 3 +- .../FindFilesToCheckCommandTest.php | 3 +- .../Target/TargetDecoratorTest.php | 3 +- .../LimitFunctionArgumentSniffTest.php | 97 +++++++++++++++++++ .../TypeHints/LimitUseStatementSniffTest.php | 96 ++++++++++++++++++ 20 files changed, 299 insertions(+), 138 deletions(-) delete mode 100644 src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php delete mode 100644 src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ParameterPerMethodLimitSniff.php create mode 100644 src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniff.php create mode 100644 src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniff.php create mode 100644 tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniffTest.php create mode 100644 tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniffTest.php diff --git a/config/phpcs/ZooRoyal/ruleset.xml b/config/phpcs/ZooRoyal/ruleset.xml index d97e5c5..c0a5639 100755 --- a/config/phpcs/ZooRoyal/ruleset.xml +++ b/config/phpcs/ZooRoyal/ruleset.xml @@ -199,13 +199,13 @@ - - + + diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php index f185baa..474349f 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php @@ -20,7 +20,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTrait; -/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class TerminalCommand extends AbstractTerminalCommand implements FixTerminalCommand, TargetTerminalCommand, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php index 89e8975..63d6b63 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php @@ -20,7 +20,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTrait; -/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class TerminalCommand extends AbstractTerminalCommand implements TargetTerminalCommand, FixTerminalCommand, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php index 3693882..e1ba79c 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php @@ -26,7 +26,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTrait; -/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class TerminalCommand extends AbstractTerminalCommand implements FixTerminalCommand, TargetTerminalCommand, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php index ab9c84b..317cb78 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php @@ -16,7 +16,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTrait; -/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class TerminalCommand extends AbstractTerminalCommand implements ExclusionTerminalCommand, FileExtensionTerminalCommand, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php index 6cd2a1f..6ba9d66 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php @@ -15,7 +15,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTrait; -/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class TerminalCommand extends AbstractTerminalCommand implements TargetTerminalCommand, FileExtensionTerminalCommand, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php index 02d2d65..bd3f7e4 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php @@ -17,7 +17,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTrait; -/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class TerminalCommand extends AbstractTerminalCommand implements TargetTerminalCommand, ExclusionTerminalCommand, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php index a5c32cc..af1223a 100644 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php +++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php @@ -16,7 +16,7 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTerminalCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTrait; -/** @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class TerminalCommand extends AbstractTerminalCommand implements TargetTerminalCommand, VerboseTerminalCommand, diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php deleted file mode 100644 index 478c9ed..0000000 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ObjectCouplingLimitSniff.php +++ /dev/null @@ -1,59 +0,0 @@ -getTokens(); - $pointer = 0; - while (($next = $file->findNext(T_USE, $pointer + 1)) !== false) { - $usesCount++; - $pointer = $next; - } - if ($usesCount > $this->maxCount) { - $className = $tokens[$file->findNext(T_STRING, $position)]['content']; - $message = sprintf(self::ERROR_MESSAGE, $className, $usesCount, $this->maxCount + 1); - $file->addError($message, $position, 'ObjectCouplingLimit'); - } - } -} diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ParameterPerMethodLimitSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ParameterPerMethodLimitSniff.php deleted file mode 100644 index 8831086..0000000 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Metrics/ParameterPerMethodLimitSniff.php +++ /dev/null @@ -1,60 +0,0 @@ -getParameterCount($file, $position); - $methodName = $file->getTokens()[$file->findNext(T_STRING, $position)]['content']; - if ($parameterCount > $this->maxCount) { - $message = sprintf(self::ERROR_MESSAGE, $methodName, $parameterCount, $this->maxCount); - $file->addError($message, $position, 'ParameterPerMethodLimit'); - } - } - - private function getParameterCount(File $file, int $position): int - { - $count = 0; - $tokens = $file->getTokens(); - $token = $tokens[$position]; - $pointer = $token['parenthesis_closer']; - for ($i = $position; $i < $pointer; $i++) { - if ($tokens[$i]['code'] === T_VARIABLE) { - $count++; - } - } - return $count; - } -} diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniff.php new file mode 100644 index 0000000..1dcafad --- /dev/null +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniff.php @@ -0,0 +1,39 @@ + $this->maximumArguments) { + $error = 'Method has too many parameters. Maximum allowed is %s, but found %s.'; + $data = [$this->maximumArguments, count($parameterNames)]; + $phpcsFile->addError($error, $stackPtr, 'TooManyArguments', $data); + } + } +} diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniff.php new file mode 100644 index 0000000..92f12c1 --- /dev/null +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniff.php @@ -0,0 +1,50 @@ + $this->maximumUseStatements) { + $error = 'Too many use statements. Maximum allowed is %s, but found %s.'; + $data = [$this->maximumUseStatements, count($usePointers[11])]; + $phpcsFile->addError($error, $stackPtr, 'TooManyUseStatements', $data); + } + } +} diff --git a/tests/Functional/CommandLine/FileSearch/FastCachedFileSearchTest.php b/tests/Functional/CommandLine/FileSearch/FastCachedFileSearchTest.php index 50b8474..34b3124 100644 --- a/tests/Functional/CommandLine/FileSearch/FastCachedFileSearchTest.php +++ b/tests/Functional/CommandLine/FileSearch/FastCachedFileSearchTest.php @@ -47,6 +47,7 @@ public function searchForFiles(): void Matchers::allOf( Matchers::containsInAnyOrder([ 'src/main/php/Sniffs/PHPCodeSniffer/.dontSniffPHP', + 'src/main/php/Sniffs/ObjectCalisthenics/.dontSniffPHP', 'tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/Fixtures/.dontSniffPHP', 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/Parameter/.dontSniffPHP', 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/ReturnType/.dontSniffPHP', @@ -73,6 +74,7 @@ public function searchForFilesIgnoringExcludedDirs(): void Matchers::allOf( Matchers::containsInAnyOrder([ 'src/main/php/Sniffs/PHPCodeSniffer/.dontSniffPHP', + 'src/main/php/Sniffs/ObjectCalisthenics/.dontSniffPHP', ]), Matchers::not( Matchers::containsInAnyOrder([ @@ -108,6 +110,7 @@ public function searchForFilesIgnoringBelowMinDepth(): void MatcherAssert::assertThat( $resultPaths, Matchers::containsInAnyOrder( + 'src/main/php/Sniffs/ObjectCalisthenics/.dontSniffPHP', 'tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/Fixtures/.dontSniffPHP', 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/Parameter/.dontSniffPHP', 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/ReturnType/.dontSniffPHP', diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php index 3d5f450..710fe2d 100644 --- a/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php +++ b/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php @@ -27,9 +27,8 @@ /** * Class ApplicationFactoryTest - * - * @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class ApplicationFactoryTest extends TestCase { private ApplicationFactory $subject; diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php index a571d27..9aaa584 100644 --- a/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php +++ b/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php @@ -25,9 +25,8 @@ /** * Class EventDispatcherFactoryTest - * - * @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class EventDispatcherFactoryTest extends TestCase { private EventDispatcherFactory $subject; diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php index 206c09c..64b1551 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php @@ -24,9 +24,8 @@ /** * Class AllToolsCommandTest - * - * @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class AllToolsCommandTest extends TestCase { private AllToolsCommand $subject; diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php index 127cdc2..c710d80 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php @@ -24,9 +24,8 @@ /** * Class FindFilesToCheckCommandTest - * - * @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class FindFilesToCheckCommandTest extends TestCase { /** @var array|array */ diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php index 27f8135..54a0a7e 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php @@ -24,9 +24,8 @@ /** * This is a very busy test and needs all the objects ;/ - * - * @phpcsSuppress ZooRoyal.Metrics.ObjectCouplingLimit */ +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class TargetDecoratorTest extends TestCase { private TargetDecorator $subject; diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniffTest.php new file mode 100644 index 0000000..20e7c7a --- /dev/null +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniffTest.php @@ -0,0 +1,97 @@ +subject = new LimitFunctionArgumentSniff(); + } + + protected function tearDown(): void + { + Mockery::close(); + } + + /** + * @test + * @dataProvider processHappyPathDataProvider + * @runInSeparateProcess + * @preserveGlobalState false + */ + public function processHappyPath(int $numberOfElements): void + { + $forgedStackPointer = 111; + $mockedFile = mock(File::class); + $mockedFunctionHelper = mock('overload:' . FunctionHelper::class); + + $mockedResult = array_pad([], $numberOfElements, 'a'); + + $mockedFunctionHelper->expects()->getParametersNames($mockedFile, $forgedStackPointer) + ->andReturn($mockedResult); + + $mockedFile->shouldNotReceive('addError'); + + $this->subject->process($mockedFile, $forgedStackPointer); + } + + /** @return array> */ + public function processHappyPathDataProvider(): array + { + return [ + 'No uses' => ['numberOfElements' => 0], + 'Some uses' => ['numberOfElements' => 10], + ]; + } + + /** + * @test + * @dataProvider processReportsErrorOnTooManyArgumentsDataProvider + * @runInSeparateProcess + * @preserveGlobalState false + */ + public function processReportsErrorOnTooManyArguments( + int $numberOfElements, + int $maximumArguments, + ): void { + $forgedStackPointer = 111; + $mockedFile = mock(File::class); + $mockedFunctionHelper = mock('overload:' . FunctionHelper::class); + + $mockedResult = array_pad([], $numberOfElements, 'a'); + + $mockedFunctionHelper->expects()->getParametersNames($mockedFile, $forgedStackPointer) + ->andReturn($mockedResult); + + $mockedFile->expects()->addError( + 'Method has too many parameters. Maximum allowed is %s, but found %s.', + $forgedStackPointer, + 'TooManyArguments', + [$maximumArguments, $numberOfElements] + ); + + $this->subject->maximumArguments = $maximumArguments; + $this->subject->process($mockedFile, $forgedStackPointer); + } + + /** @return array> */ + public function processReportsErrorOnTooManyArgumentsDataProvider(): array + { + return [ + 'Too many arguments' => ['numberOfElements' => 20, 'maximumArguments' => 10], + 'Exactly over maximum arguments' => ['numberOfElements' => 11, 'maximumArguments' => 10], + 'Different limit' => ['numberOfElements' => 4, 'maximumArguments' => 3], + ]; + } +} diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniffTest.php new file mode 100644 index 0000000..a472ab7 --- /dev/null +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniffTest.php @@ -0,0 +1,96 @@ +subject = new LimitUseStatementSniff(); + } + + protected function tearDown(): void + { + Mockery::close(); + } + + /** + * @test + * @dataProvider processHappyPathDataProvider + * @runInSeparateProcess + * @preserveGlobalState false + */ + public function processHappyPath(int $numberOfElements): void + { + $mockedFile = mock(File::class); + $mockedUserStatementHelper = mock('overload:' . UseStatementHelper::class); + + $mockedResult = array_pad([], $numberOfElements, 'a'); + + $mockedUserStatementHelper->expects()->getFileUseStatements($mockedFile) + ->andReturn([11 => $mockedResult]); + + $mockedFile->shouldNotReceive('addError'); + + $this->subject->process($mockedFile, 10); + } + + /** @return array> */ + public function processHappyPathDataProvider(): array + { + return [ + 'No uses' => ['numberOfElements' => 0], + 'Some uses' => ['numberOfElements' => 10], + ]; + } + + /** + * @test + * @dataProvider processReportsErrorOnTooManyUsesDataProvider + * @runInSeparateProcess + * @preserveGlobalState false + */ + public function processReportsErrorOnTooManyUses( + int $numberOfElements, + int $maximumUseStatements, + ): void { + $forgedStackPointer = 10; + $mockedFile = mock(File::class); + $mockedUserStatementHelper = mock('overload:' . UseStatementHelper::class); + + $mockedResult = array_pad([], $numberOfElements, 'a'); + + $mockedUserStatementHelper->expects()->getFileUseStatements($mockedFile) + ->andReturn([11 => $mockedResult]); + + $mockedFile->expects()->addError( + 'Too many use statements. Maximum allowed is %s, but found %s.', + $forgedStackPointer, + 'TooManyUseStatements', + [$maximumUseStatements, $numberOfElements] + ); + + $this->subject->maximumUseStatements = $maximumUseStatements; + $this->subject->process($mockedFile, $forgedStackPointer); + } + + /** @return array> */ + public function processReportsErrorOnTooManyUsesDataProvider(): array + { + return [ + 'Too many uses' => ['numberOfElements' => 20, 'maximumUseStatements' => 15 ], + 'Exactly over the limit' => ['numberOfElements' => 16, 'maximumUseStatements' => 15], + 'Different Limit' => ['numberOfElements' => 4, 'maximumUseStatements' => 3], + ]; + } +} From ff1e1d5a80914aefe41c1c8349055b6fc56c11ca Mon Sep 17 00:00:00 2001 From: Patrick Janzen Date: Tue, 25 Mar 2025 14:05:24 +0100 Subject: [PATCH 24/32] phpmd removal --- composer.json | 225 +++++++++--------- config/phpmd/phpmd.xml | 14 -- infection.json.dist | 2 +- .../ApplicationFactory.php | 1 - .../PHPMessDetector/.dontCopyPasteDetectPHP | 0 .../PHPMessDetectorCommand.php | 47 ---- .../PHPMessDetector/TerminalCommand.php | 104 -------- .../ZooRoyal/Helper/ClassAnalyzer.php | 24 +- .../Commenting/DocCommentAlignmentSniff.php | 1 - .../Sniffs/Commenting/DocCommentSniff.php | 1 - .../FunctionCommentThrowTagSniff.php | 1 - .../Safe/CheckSafeFunctionUsageSniff.php | 5 + tests/System/Complete/GlobalSystemTest.php | 1 - .../ApplicationFactoryTest.php | 1 - .../PHPMessDetectorCommandTest.php | 57 ----- .../PHPMessDetector/TerminalCommandTest.php | 173 -------------- .../Sniffs/Naming/NameLengthSniffTest.php | 73 +++++- .../Safe/CheckSafeFunctionUsageSniffTest.php | 53 ++++- vendor-bin/phpmd/composer.json | 5 - 19 files changed, 229 insertions(+), 559 deletions(-) delete mode 100644 config/phpmd/phpmd.xml delete mode 100644 src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/.dontCopyPasteDetectPHP delete mode 100644 src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommand.php delete mode 100644 src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php delete mode 100644 tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommandTest.php delete mode 100644 tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php delete mode 100644 vendor-bin/phpmd/composer.json diff --git a/composer.json b/composer.json index 99d9e1b..e57c327 100644 --- a/composer.json +++ b/composer.json @@ -1,118 +1,117 @@ { - "name": "zooroyal/coding-standard-source", - "description": "This is the ZooRoyal coding standard source package.", - "type": "phpcodesniffer-standard", - "keywords": [ - "ZooRoyal", - "phpcs", - "standards", - "phpmd", - "phpcpd", - "lint" - ], - "homepage": "https://github.com/ZooRoyal/coding-standard-source", - "license": "BSD-3-Clause", - "authors": [ - { - "name": "Sebastian Knott", - "email": "sebastian.knott@rewe-digital.com" - } - ], - "support": { - "issues": "https://github.com/ZooRoyal/coding-standard-source/issues", - "wiki": "https://github.com/ZooRoyal/coding-standard-source/wiki", - "source": "https://github.com/ZooRoyal/coding-standard-source" - }, - "require": { - "php": "^8.4.0", - "ext-json": "*", - "ext-xml": "*", - "composer-runtime-api": "^2.0", - "bamarni/composer-bin-plugin": "^1.8", - "composer/semver": "^3.4", - "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", - "nette/neon": "^3.3", - "nette/utils": "^4.0", - "nikic/php-parser": "^5.4.0", - "php-di/php-di": "^7.0.1", - "slevomat/coding-standard": "^8.10.0", - "squizlabs/php_codesniffer": "^3.9.0", - "symfony/console": " ^7.2.1", - "symfony/event-dispatcher": "^7.2.0", - "symfony/filesystem": " ^7.2.0", - "symfony/process": " ^7.2.0", - "thecodingmachine/safe": "^3.0.1", - "webmozart/path-util": "^2.3" - }, - "require-dev": { - "amphp/amp": "^v2.6.2", - "amphp/phpunit-util": "^2.0.0", - "amphp/process": "^v1.1.4", - "brianium/paratest": "^v6.11.1", - "infection/infection": ">=0.29.12", - "mockery/mockery": "1.6.11", - "phpunit/phpunit": "^9.6.16", - "roave/security-advisories": "dev-latest", - "sebastianknott/hamcrest-object-accessor": "^3.0.0" - }, - "replace": { - "zooroyal/coding-standard": "self.version" - }, - "autoload": { - "psr-4": { - "Zooroyal\\CodingStandard\\": "src/main/php/" - } - }, - "autoload-dev": { - "psr-4": { - "Zooroyal\\CodingStandard\\Tests\\": "tests/" - }, - "files": [ - "vendor/squizlabs/php_codesniffer/autoload.php", - "vendor/squizlabs/php_codesniffer/src/Util/Tokens.php", - "vendor/squizlabs/php_codesniffer/src/Sniffs/Sniff.php", - "vendor/slevomat/coding-standard/autoload-bootstrap.php" - ] - }, - "bin": [ - "src/bin/coding-standard" - ], - "scripts": { - "post-update-cmd": "npm update", - "post-install-cmd": "npm install", - "ci": [ - "@test-prepare", - "@test", - "@infection-command" + "name": "zooroyal/coding-standard-source", + "description": "This is the ZooRoyal coding standard source package.", + "type": "phpcodesniffer-standard", + "keywords": [ + "ZooRoyal", + "phpcs", + "standards", + "phpcpd", + "lint" ], - "test-mkdirs": "mkdir -p tmp/phpunit", - "test-paratest-command": "paratest -p$(getconf _NPROCESSORS_ONLN)", - "test-prepare": "mkdir -p tmp/phpunit", - "test": [ - "@test-prepare", - "@test-paratest-command" + "homepage": "https://github.com/ZooRoyal/coding-standard-source", + "license": "BSD-3-Clause", + "authors": [ + { + "name": "Sebastian Knott", + "email": "sebastian.knott@rewe-digital.com" + } ], - "infection-command": "infection -n --threads=$(getconf _NPROCESSORS_ONLN) --skip-initial-tests --coverage=tmp/phpunit --no-progress", - "infection": [ - "@test-prepare", - "@test --testsuite=InfectionRelevant", - "@infection-command" - ] - }, - "config": { - "optimize-autoloader": true, - "sort-packages": true, - "process-timeout": 600, - "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true, - "infection/extension-installer": true, - "bamarni/composer-bin-plugin": true - } - }, - "extra": { - "bamarni-bin": { - "bin-links": true, - "forward-command": true + "support": { + "issues": "https://github.com/ZooRoyal/coding-standard-source/issues", + "wiki": "https://github.com/ZooRoyal/coding-standard-source/wiki", + "source": "https://github.com/ZooRoyal/coding-standard-source" + }, + "require": { + "php": "^8.4.0", + "ext-json": "*", + "ext-xml": "*", + "composer-runtime-api": "^2.0", + "bamarni/composer-bin-plugin": "^1.8", + "composer/semver": "^3.4", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", + "nette/neon": "^3.3", + "nette/utils": "^4.0", + "nikic/php-parser": "^5.4.0", + "php-di/php-di": "^7.0.1", + "slevomat/coding-standard": "^8.10.0", + "squizlabs/php_codesniffer": "^3.9.0", + "symfony/console": " ^7.2.1", + "symfony/event-dispatcher": "^7.2.0", + "symfony/filesystem": " ^7.2.0", + "symfony/process": " ^7.2.0", + "thecodingmachine/safe": "^3.0.1", + "webmozart/path-util": "^2.3" + }, + "require-dev": { + "amphp/amp": "^v2.6.2", + "amphp/phpunit-util": "^2.0.0", + "amphp/process": "^v1.1.4", + "brianium/paratest": "^v6.11.1", + "infection/infection": ">=0.29.12", + "mockery/mockery": "1.6.11", + "phpunit/phpunit": "^9.6.16", + "roave/security-advisories": "dev-latest", + "sebastianknott/hamcrest-object-accessor": "^3.0.0" + }, + "replace": { + "zooroyal/coding-standard": "self.version" + }, + "autoload": { + "psr-4": { + "Zooroyal\\CodingStandard\\": "src/main/php/" + } + }, + "autoload-dev": { + "psr-4": { + "Zooroyal\\CodingStandard\\Tests\\": "tests/" + }, + "files": [ + "vendor/squizlabs/php_codesniffer/autoload.php", + "vendor/squizlabs/php_codesniffer/src/Util/Tokens.php", + "vendor/squizlabs/php_codesniffer/src/Sniffs/Sniff.php", + "vendor/slevomat/coding-standard/autoload-bootstrap.php" + ] + }, + "bin": [ + "src/bin/coding-standard" + ], + "scripts": { + "post-update-cmd": "npm update", + "post-install-cmd": "npm install", + "ci": [ + "@test-prepare", + "@test", + "@infection-command" + ], + "test-mkdirs": "mkdir -p tmp/phpunit", + "test-paratest-command": "paratest -p$(getconf _NPROCESSORS_ONLN)", + "test-prepare": "mkdir -p tmp/phpunit", + "test": [ + "@test-prepare", + "@test-paratest-command" + ], + "infection-command": "infection -n --threads=$(getconf _NPROCESSORS_ONLN) --skip-initial-tests --coverage=tmp/phpunit --no-progress", + "infection": [ + "@test-prepare", + "@test-paratest-command --testsuite=InfectionRelevant", + "@infection-command" + ] + }, + "config": { + "optimize-autoloader": true, + "sort-packages": true, + "process-timeout": 600, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true, + "infection/extension-installer": true, + "bamarni/composer-bin-plugin": true + } + }, + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": true + } } - } } diff --git a/config/phpmd/phpmd.xml b/config/phpmd/phpmd.xml deleted file mode 100644 index 8d18d96..0000000 --- a/config/phpmd/phpmd.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - ZooRoyal Ruleset for PHP MessDetector - - - - - - - diff --git a/infection.json.dist b/infection.json.dist index ed27bea..e07aa18 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -1,7 +1,7 @@ { "timeout": 20, "minMsi": 87, - "minCoveredMsi": 94, + "minCoveredMsi": 95, "source": { "directories": [ "src\/main\/php" diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php b/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php index 47a713d..e940012 100644 --- a/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php +++ b/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php @@ -33,7 +33,6 @@ class ApplicationFactory PHPCodeSnifferCommand::class, PHPCopyPasteDetectorCommand::class, PHPParallelLintCommand::class, - PHPMessDetectorCommand::class, PHPStanCommand::class, JSESLintCommand::class, JSStyleLintCommand::class, diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/.dontCopyPasteDetectPHP b/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/.dontCopyPasteDetectPHP deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommand.php deleted file mode 100644 index 73d0bae..0000000 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommand.php +++ /dev/null @@ -1,47 +0,0 @@ - */ - protected array $allowedFileEndings = ['php']; - - /** - * {@inheritDoc} - */ - #[Override] - protected function configure(): void - { - parent::configure(); - $this->setName('sca:mess-detect'); - $this->setDescription('Run PHP-MD on PHP files.'); - $this->setHelp( - 'This tool executes PHP-MD on a certain set of PHP files of this project. It ignores files which are in ' - . 'directories with a .dontMessDetectPHP file. Subdirectories are ignored too.', - ); - $this->terminalCommandName = 'PHP Mess Detector'; - } - - /** - * This method accepts all dependencies needed to use this class properly. - * It's annotated for use with PHP-DI. - * - * @see http://php-di.org/doc/annotations.html - */ - #[Inject] - public function injectDependenciesCommand(Container $container): void - { - $this->terminalCommand = $container->make(TerminalCommand::class); - } -} diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php deleted file mode 100644 index 6ba9d66..0000000 --- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php +++ /dev/null @@ -1,104 +0,0 @@ -validateTargets(); - - $vendorPath = $this->environment->getVendorDirectory()->getRealPath(); - $phpMessDetectorConfig = $this->environment->getPackageDirectory()->getRealPath() - . '/config/phpmd/phpmd.xml'; - - $terminalApplication = $vendorPath . '/bin/phpmd'; - - $sprintfCommand = sprintf( - self::TEMPLATE, - $terminalApplication, - $this->buildTargetingString(), - $phpMessDetectorConfig, - $this->buildExcludingString(), - $this->buildExtensionString(), - ); - - $this->command = $sprintfCommand; - $this->commandParts = explode(' ', $sprintfCommand); - } - - /** - * This method returns the string representation of the excluded files list. - */ - private function buildExcludingString(): string - { - $excludingString = ''; - if ($this->excludesFiles !== []) { - $excludingString = ' --exclude '; - $excludesFilePaths = array_map( - static fn(EnhancedFileInfo $item) => $item->getRealPath(), - $this->excludesFiles, - ); - $excludingString .= implode(',', $excludesFilePaths); - } - return $excludingString; - } - - /** - * This method returns the string representation of the targeted files list. - */ - private function buildTargetingString(): string - { - if ($this->targetedFiles !== null) { - $targetedFilePaths = array_map( - static fn(EnhancedFileInfo $item) => $item->getRealPath(), - $this->targetedFiles, - ); - $targetingString = implode(',', $targetedFilePaths); - } else { - $targetingString = $this->environment->getRootDirectory()->getRealPath(); - } - return $targetingString; - } - - private function buildExtensionString(): string - { - $extensionString = ''; - if ($this->fileExtensions !== []) { - $extensionString = ' --suffixes '; - $extensionString .= implode(',', $this->fileExtensions); - } - return $extensionString; - } -} diff --git a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/ClassAnalyzer.php b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/ClassAnalyzer.php index c49aad2..7a93a6f 100644 --- a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/ClassAnalyzer.php +++ b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/ClassAnalyzer.php @@ -10,17 +10,16 @@ final class ClassAnalyzer { + const int ONE = 1; /** @var array */ private static array $propertyList = []; public static function getClassMethodCount(File $file, int $position): int { - self::ensureIsClassTraitOrInterface($file, $position); - $methodCount = 0; $pointer = $position; - while (($next = $file->findNext(T_FUNCTION, $pointer + 1)) !== false) { + while (($next = $file->findNext(T_FUNCTION, $pointer + self::ONE)) !== false) { ++$methodCount; $pointer = $next; @@ -45,8 +44,8 @@ public static function getClassProperties(File $file, int $position): array self::$propertyList = []; - while (($pointer = $file->findNext(T_VARIABLE, ($pointer + 1), $token['scope_closer'])) !== false) { - self::extractPropertyIfFound($file, (int) $pointer); + while (($pointer = $file->findNext(T_VARIABLE, ($pointer + self::ONE), $token['scope_closer'])) !== false) { + self::extractPropertyIfFound($file, $pointer); } return self::$propertyList; @@ -59,20 +58,5 @@ private static function extractPropertyIfFound(File $file, int $position): void } } - private static function ensureIsClassTraitOrInterface(File $file, int $position): void - { - $token = $file->getTokens()[$position]; - - self::ensureIsClassLikeToken($token); - } - - private static function ensureIsClassLikeToken(array $token): void - { - if (in_array($token['code'], [T_CLASS, T_INTERFACE, T_TRAIT], true)) { - return; - } - $message = sprintf('Must be class, interface or trait. "%s" given.', ltrim($token['type'], 'T_')); - throw new NonClassTypeTokenTypeException($message); - } } diff --git a/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentAlignmentSniff.php b/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentAlignmentSniff.php index 208dda1..1e54925 100644 --- a/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentAlignmentSniff.php +++ b/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentAlignmentSniff.php @@ -30,7 +30,6 @@ * * This version ignores OpenAPI (OA) comments that may be deeply nested. * - * @SuppressWarnings(PHPMD) */ class DocCommentAlignmentSniff implements Sniff { diff --git a/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentSniff.php b/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentSniff.php index 6e8e3c7..9ad03b6 100644 --- a/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentSniff.php +++ b/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentSniff.php @@ -69,7 +69,6 @@ public function register() * @param int $stackPtr The position of the current token * in the stack passed in $tokens. * - * @SuppressWarnings(PHPMD) * * @return void */ diff --git a/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniff.php b/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniff.php index aa0010e..2eb3bfb 100644 --- a/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniff.php +++ b/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniff.php @@ -36,7 +36,6 @@ public function register() * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position of the current token * in the stack passed in $tokens. - * @SuppressWarnings(PHPMD) * * @return void */ diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php index feaad45..fdcbfe2 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php @@ -14,6 +14,7 @@ use SlevomatCodingStandard\Helpers\TokenHelper; use SlevomatCodingStandard\Helpers\UseStatement; use SlevomatCodingStandard\Helpers\UseStatementHelper; +use Symfony\Component\Filesystem\Filesystem; use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\ComposerInterpreter; @@ -36,8 +37,12 @@ public function __construct() list($major, $minor) = explode('.', $phpversion); $environment = $container->get(Environment::class); + $fileSystem = $container->get(Filesystem::class); $path = $environment->getRootDirectory()->getRealPath() . '/vendor/thecodingmachine/safe/generated/' . $major . '.' . $minor . '/'; + if (!$fileSystem->exists($path)) { + throw new DirException(sprintf('Path "%s" does not exist!', $path), 1742901391); + } try { // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged $filesUnfiltered = @scandir($path); diff --git a/tests/System/Complete/GlobalSystemTest.php b/tests/System/Complete/GlobalSystemTest.php index 5878394..fbbf620 100644 --- a/tests/System/Complete/GlobalSystemTest.php +++ b/tests/System/Complete/GlobalSystemTest.php @@ -54,7 +54,6 @@ public function dontFilesMakeAllGood(): void $dotFiles = [ '.dontSniffPHP', - '.dontMessDetectPHP', '.dontCopyPasteDetectPHP', '.dontLintPHP', '.dontSniffLESS', diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php index 710fe2d..b218d1a 100644 --- a/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php +++ b/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php @@ -41,7 +41,6 @@ class ApplicationFactoryTest extends TestCase PHPCodeSnifferCommand::class, PHPStanCommand::class, FindFilesToCheckCommand::class, - PHPMessDetectorCommand::class, PHPCopyPasteDetectorCommand::class, JSESLintCommand::class, JSStyleLintCommand::class, diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommandTest.php deleted file mode 100644 index ab7d807..0000000 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommandTest.php +++ /dev/null @@ -1,57 +0,0 @@ -terminalCommandName = 'PHP Mess Detector'; - $this->terminalCommandType = TerminalCommand::class; - $this->exclusionToken = '.dontMessDetectPHP'; - $this->allowedFileEndings = ['php']; - $this->mockedTerminalCommand = Mockery::mock(TerminalCommand::class); - $this->mockedContainer = Mockery::mock(Container::class); - - $this->mockedContainer->shouldReceive('make')->atLeast()->once() - ->with(TerminalCommand::class) - ->andReturn($this->mockedTerminalCommand); - - parent::setUp(); - - $this->subject = new PHPMessDetectorCommand($this->mockedTargetableInputFacet); - $this->subject->injectDependenciesToolCommand( - $this->mockedTerminalCommandRunner, - $this->mockedEventDispatcher, - ); - $this->subject->injectDependenciesCommand($this->mockedContainer); - } - - /** - * @test - */ - public function configureSetsCorrectAttributes(): void - { - self::assertSame('sca:mess-detect', $this->subject->getName()); - self::assertSame('Run PHP-MD on PHP files.', $this->subject->getDescription()); - self::assertSame( - 'This tool executes PHP-MD on a certain set of PHP files of this project. It ignores files which are in ' - . 'directories with a .dontMessDetectPHP file. Subdirectories are ignored too.', - $this->subject->getHelp(), - ); - } -} diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php deleted file mode 100644 index a89961a..0000000 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php +++ /dev/null @@ -1,173 +0,0 @@ -mockedEnvironment = Mockery::mock(Environment::class); - $this->mockedOutput = Mockery::mock(OutputInterface::class); - - $this->mockedEnvironment->shouldReceive('getPackageDirectory->getRealPath') - ->andReturn(self::FORGED_PACKAGE_DIRECTORY); - $this->mockedEnvironment->shouldReceive('getRootDirectory->getRelativePathname') - ->andReturn(self::FORGED_RELATIV_ROOT); - $this->mockedEnvironment->shouldReceive('getRootDirectory->getRealPath') - ->andReturn(self::FORGED_ABSOLUTE_ROOT); - $this->mockedEnvironment->shouldReceive('getVendorDirectory->getRealPath') - ->andReturn(self::FORGED_ABSOLUTE_VENDOR); - - $this->subject = new TerminalCommand($this->mockedEnvironment); - $this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput); - } - - #[Override] - public function tearDown(): void - { - Mockery::close(); - } - - /** - * @test - * @dataProvider terminalCommandCompilationDataProvider - */ - public function terminalCommandCompilation(TerminalCommandTestData $data): void - { - $this->mockedOutput->shouldReceive('writeln')->once() - ->with( - Matchers::startsWith( - 'Compiled TerminalCommand to following string' - . PHP_EOL . $data->getExpectedCommand(), - ), - OutputInterface::VERBOSITY_VERY_VERBOSE, - ); - - $this->subject->addAllowedFileExtensions($data->getExtensions()); - $this->subject->addExclusions($data->getExcluded()); - if ($data->getTargets() !== null) { - $this->subject->addTargets($data->getTargets()); - } - - $result = (string) $this->subject; - $resultingArray = $this->subject->toArray(); - - self::assertSame($data->getExpectedCommand(), $result); - self::assertSame($result, implode(' ', $resultingArray)); - } - - /** - * This data provider needs to be long because it contains all testing data. - * - * @return array> - */ - // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength - public function terminalCommandCompilationDataProvider(): array - { - $mockedEnhancedFileInfoExcluded1 = Mockery::mock(EnhancedFileInfo::class); - $mockedEnhancedFileInfoExcluded1->shouldReceive('getRealPath') - ->andReturnValues(['a', 'b']); - $mockedEnhancedFileInfoExcluded2 = Mockery::mock(EnhancedFileInfo::class); - $mockedEnhancedFileInfoExcluded2->shouldReceive('getRealPath') - ->andReturnValues(['a', 'b']); - $mockedEnhancedFileInfoTarget1 = Mockery::mock(EnhancedFileInfo::class); - $mockedEnhancedFileInfoTarget1->shouldReceive('getRealPath') - ->andReturnValues(['c', 'd']); - $mockedEnhancedFileInfoTarget2 = Mockery::mock(EnhancedFileInfo::class); - $mockedEnhancedFileInfoTarget2->shouldReceive('getRealPath') - ->andReturnValues(['c', 'd']); - - return [ - 'all' => [ - new TerminalCommandTestData( - [ - 'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR . '/bin/phpmd c,d text ' - . self::FORGED_PACKAGE_DIRECTORY - . '/config/phpmd/phpmd.xml --suffixes qweasd,argh --exclude a,b', - 'excluded' => [$mockedEnhancedFileInfoExcluded1, $mockedEnhancedFileInfoExcluded1], - 'extensions' => ['qweasd', 'argh'], - 'targets' => [$mockedEnhancedFileInfoTarget1, $mockedEnhancedFileInfoTarget1], - ], - ), - ], - 'empty optionals' => [ - new TerminalCommandTestData( - [ - 'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR . '/bin/phpmd ' - . self::FORGED_ABSOLUTE_ROOT . ' text ' . self::FORGED_PACKAGE_DIRECTORY - . '/config/phpmd/phpmd.xml', - ], - ), - ], - 'excluding' => [ - new TerminalCommandTestData( - [ - 'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR . '/bin/phpmd ' - . self::FORGED_ABSOLUTE_ROOT . ' text ' . self::FORGED_PACKAGE_DIRECTORY - . '/config/phpmd/phpmd.xml --exclude a,b', - 'excluded' => [$mockedEnhancedFileInfoExcluded2, $mockedEnhancedFileInfoExcluded2], - ], - ), - ], - 'extensions' => [ - new TerminalCommandTestData( - [ - 'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR . '/bin/phpmd ' - . self::FORGED_ABSOLUTE_ROOT . ' text ' . self::FORGED_PACKAGE_DIRECTORY - . '/config/phpmd/phpmd.xml --suffixes asdqwe,qweasd', - 'extensions' => ['asdqwe', 'qweasd'], - ], - ), - ], - 'targeted' => [ - new TerminalCommandTestData( - [ - 'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR . '/bin/phpmd c,d text ' . - self::FORGED_PACKAGE_DIRECTORY . '/config/phpmd/phpmd.xml', - 'targets' => [$mockedEnhancedFileInfoTarget2, $mockedEnhancedFileInfoTarget2], - ], - ), - ], - ]; - } - - /** - * @test - */ - public function terminalCommandCompilationThrowsExceptionOnNoFilesToCheck(): void - { - $this->expectException(NoUsefulCommandFoundException::class); - $this->expectExceptionCode(1620831304); - $this->expectExceptionMessage('It makes no sense to sniff no files.'); - - $this->subject->addTargets([]); - - $this->subject->__toString(); - } -} diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniffTest.php index 3e49e67..548ee83 100644 --- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniffTest.php +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniffTest.php @@ -20,6 +20,11 @@ protected function setUp(): void $this->subject = new NameLengthSniff(); } + protected function tearDown(): void + { + Mockery::close(); + } + /** * @test * @dataProvider processHappyPathDataProvider @@ -41,11 +46,12 @@ public function processHappyPathDataProvider(): array { return [ 'Good Name' => ['name' => 'aaaaaaa'], - 'i' => ['name' => 'i'], + 'Almost too short name' => ['name' => 'aaa'], + 'Almost too long name' => ['name' => str_pad('a', 70, 'a')], + 'i' => ['name' => '$i'], ]; } - /** * @test * @runInSeparateProcess @@ -86,21 +92,21 @@ public function processReportsErrorIfClassysAreBadDataProvider(): array return [ 'class too short' => [ 'token' => 'class', - 'name' => '$a', + 'name' => 'aa', 'errorMessage' => 'Name "%s" is less than %s characters long', 'code' => 'NameTooShort', 'length' => 3, ], 'class too long' => [ 'token' => 'class', - 'name' => str_pad('$', 71, 'a'), + 'name' => str_pad('', 71, 'a'), 'errorMessage' => 'Name "%s" is greater than %s characters long', 'code' => 'NameTooLong', - 'length' => 60, + 'length' => 70, ], 'trait too short' => [ 'token' => 'trait', - 'name' => '$a', + 'name' => 'aa', 'errorMessage' => 'Name "%s" is less than %s characters long', 'code' => 'NameTooShort', 'length' => 3, @@ -110,11 +116,11 @@ public function processReportsErrorIfClassysAreBadDataProvider(): array 'name' => str_pad('$', 71, 'a'), 'errorMessage' => 'Name "%s" is greater than %s characters long', 'code' => 'NameTooLong', - 'length' => 60, + 'length' => 70, ], 'interface too short' => [ 'token' => 'interface', - 'name' => '$a', + 'name' => 'aa', 'errorMessage' => 'Name "%s" is less than %s characters long', 'code' => 'NameTooShort', 'length' => 3, @@ -124,7 +130,7 @@ public function processReportsErrorIfClassysAreBadDataProvider(): array 'name' => str_pad('$', 71, 'a'), 'errorMessage' => 'Name "%s" is greater than %s characters long', 'code' => 'NameTooLong', - 'length' => 60, + 'length' => 70, ], ]; } @@ -173,7 +179,7 @@ public function processReportsErrorIfFunctionIsBadDataProvider(): array 'functionName' => str_pad('a', 71, 'a'), 'errorMessage' => 'Name "%s" is greater than %s characters long', 'code' => 'NameTooLong', - 'length' => 60, + 'length' => 70, ], ]; } @@ -215,10 +221,10 @@ public function processReportsErrorIfVariableIsBadDataProvider(): array 'length' => 3, ], 'too long' => [ - 'variable' => str_pad('$', 71, 'a'), + 'variable' => str_pad('$', 72, 'a'), 'errorMessage' => 'Name "%s" is greater than %s characters long', 'code' => 'NameTooLong', - 'length' => 60, + 'length' => 70, ], ]; } @@ -231,4 +237,47 @@ public function registerReturnsExpectedTokens(): void $expected = [T_VARIABLE, T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT, T_PROPERTY]; $this->assertEquals($expected, $this->subject->register()); } + + /** + * @test + */ + public function processWithConfiguredMaximum() + { + $mockedFile = mock(File::class); + $forgedStackPointer = 0; + $variable = str_pad('$', 40, 'a'); + $forgedTokens = [ $forgedStackPointer => ['content' => $variable]]; + + $mockedFile->expects()->getTokens()->andReturn($forgedTokens); + $mockedFile->expects()->addError( + 'Name "%s" is greater than %s characters long', + $forgedStackPointer, + 'NameTooLong', + [ltrim($variable, '$'), 30] + ); + + $this->subject->maximumLength = 30; + $this->subject->process($mockedFile, $forgedStackPointer); + } + /** + * @test + */ + public function processWithConfiguredMinimum() + { + $mockedFile = mock(File::class); + $forgedStackPointer = 0; + $variable = str_pad('$', 29, 'a'); + $forgedTokens = [ $forgedStackPointer => ['content' => $variable]]; + + $mockedFile->expects()->getTokens()->andReturn($forgedTokens); + $mockedFile->expects()->addError( + 'Name "%s" is less than %s characters long', + $forgedStackPointer, + 'NameTooShort', + [ltrim($variable, '$'), 30] + ); + + $this->subject->minimumLength = 30; + $this->subject->process($mockedFile, $forgedStackPointer); + } } diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php index 7d2426e..4910761 100644 --- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php @@ -11,6 +11,8 @@ use PHP_CodeSniffer\Sniffs\Sniff; use PHPUnit\Framework\TestCase; use RuntimeException; +use Safe\Exceptions\DirException; +use Symfony\Component\Filesystem\Filesystem; use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\ComposerInterpreter; @@ -18,13 +20,6 @@ class CheckSafeFunctionUsageSniffTest extends TestCase { - #[Override] - protected function tearDown(): void - { - Mockery::close(); - parent::tearDown(); - } - /** * @test */ @@ -47,11 +42,15 @@ public function notFoundSafeLibrarySkipsProcess(): void $mockedEnvironment = Mockery::mock(Environment::class); $mockedFile = Mockery::mock(File::class); $mockedComposerInterpreter = Mockery::mock(ComposerInterpreter::class); + $mockedFilesystem = mock(Filesystem::class); $mockedContainerFactory->expects()->getContainerInstance()->andReturn($mockedContainer); $mockedContainer->expects()->get(Environment::class)->andReturn($mockedEnvironment); $mockedContainer->expects()->get(ComposerInterpreter::class)->andReturn($mockedComposerInterpreter); + $mockedContainer->expects()->get(Filesystem::class)->andReturn($mockedFilesystem); $mockedEnvironment->shouldReceive('getRootDirectory->getRealPath')->andReturn('/foo/bar'); + $mockedFilesystem->expects()->exists('/foo/bar/vendor/thecodingmachine/safe/generated/8.4/')->andReturn(true); + $mockedComposerInterpreter->expects()->getMinimalViablePhpVersion()->andReturn('8.4.3'); $this->expectExceptionObject( @@ -65,6 +64,39 @@ public function notFoundSafeLibrarySkipsProcess(): void $subject->process($mockedFile, 0); } + /** + * @test + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function notFoundSafeVersionLibraryThrowsError(): void + { + $mockedContainerFactory = Mockery::mock('overload:' . ContainerFactory::class); + $mockedContainer = Mockery::mock(Container::class); + $mockedEnvironment = Mockery::mock(Environment::class); + $mockedComposerInterpreter = Mockery::mock(ComposerInterpreter::class); + $mockedFilesystem = mock(Filesystem::class); + + $mockedContainerFactory->expects()->getContainerInstance()->andReturn($mockedContainer); + $mockedContainer->expects()->get(Environment::class)->andReturn($mockedEnvironment); + $mockedContainer->expects()->get(ComposerInterpreter::class)->andReturn($mockedComposerInterpreter); + $mockedComposerInterpreter->expects()->getMinimalViablePhpVersion()->andReturn('8.4.3'); + $mockedContainer->expects()->get(Filesystem::class)->andReturn($mockedFilesystem); + $mockedEnvironment->shouldReceive('getRootDirectory->getRealPath')->andReturn('/foo/bar'); + $mockedFilesystem->expects()->exists('/foo/bar/vendor/thecodingmachine/safe/generated/8.4/')->andReturn(false); + + try { + $subject = new CheckSafeFunctionUsageSniff(); + } catch (DirException $exception) { + self::assertSame( + 'Path "/foo/bar/vendor/thecodingmachine/safe/generated/8.4/" does not exist!', + $exception->getMessage() + ); + self::assertSame(1742901391 , $exception->getCode()); + } + } + /** * @test */ @@ -75,4 +107,11 @@ public function registerReturnsCorrectTokenArray(): void self::assertSame([T_STRING], $result); } + + #[Override] + protected function tearDown(): void + { + Mockery::close(); + parent::tearDown(); + } } diff --git a/vendor-bin/phpmd/composer.json b/vendor-bin/phpmd/composer.json deleted file mode 100644 index 721dc94..0000000 --- a/vendor-bin/phpmd/composer.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "require": { - "phpmd/phpmd": "^2.13.0" - } -} From 2230ddcd05061cf5f250eba4563bdb3e7ca66050 Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Tue, 25 Mar 2025 15:50:06 +0100 Subject: [PATCH 25/32] Mention Safe version in exception --- .../Safe/CheckSafeFunctionUsageSniff.php | 5 ++++- .../Safe/CheckSafeFunctionUsageSniffTest.php | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php index fdcbfe2..4712e94 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php @@ -41,7 +41,10 @@ public function __construct() $path = $environment->getRootDirectory()->getRealPath() . '/vendor/thecodingmachine/safe/generated/' . $major . '.' . $minor . '/'; if (!$fileSystem->exists($path)) { - throw new DirException(sprintf('Path "%s" does not exist!', $path), 1742901391); + throw new DirException( + sprintf('Path "%s" does not exist! Did you install thecodingmachine/safe >= 3', $path), + 1742901391 + ); } try { // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php index 4910761..d47cb5d 100644 --- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php @@ -20,6 +20,13 @@ class CheckSafeFunctionUsageSniffTest extends TestCase { + #[Override] + protected function tearDown(): void + { + Mockery::close(); + parent::tearDown(); + } + /** * @test */ @@ -90,10 +97,11 @@ public function notFoundSafeVersionLibraryThrowsError(): void $subject = new CheckSafeFunctionUsageSniff(); } catch (DirException $exception) { self::assertSame( - 'Path "/foo/bar/vendor/thecodingmachine/safe/generated/8.4/" does not exist!', + 'Path "/foo/bar/vendor/thecodingmachine/safe/generated/8.4/" does not exist! ' + . 'Did you install thecodingmachine/safe >= 3', $exception->getMessage() ); - self::assertSame(1742901391 , $exception->getCode()); + self::assertSame(1742901391, $exception->getCode()); } } @@ -107,11 +115,4 @@ public function registerReturnsCorrectTokenArray(): void self::assertSame([T_STRING], $result); } - - #[Override] - protected function tearDown(): void - { - Mockery::close(); - parent::tearDown(); - } } From 6d4f6b63e47fb654463199579ac61094d993aad6 Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Thu, 27 Mar 2025 14:48:59 +0100 Subject: [PATCH 26/32] Cleanup Implementation --- .../CommandLine/ApplicationLifeCycle/ApplicationFactory.php | 1 - .../ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php | 1 + .../ApplicationLifeCycle/ApplicationFactoryTest.php | 1 - .../Standards/ZooRoyal/Sniffs/Naming/NameLengthSniffTest.php | 4 ++-- .../ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php b/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php index e940012..862e575 100644 --- a/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php +++ b/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php @@ -13,7 +13,6 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\JSStyleLint\JSStyleLintCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCodeSniffer\PHPCodeSnifferCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCopyPasteDetector\PHPCopyPasteDetectorCommand; -use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPMessDetector\PHPMessDetectorCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPParallelLint\PHPParallelLintCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPStan\PHPStanCommand; diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php index 4712e94..a220516 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php @@ -22,6 +22,7 @@ use function Safe\file_get_contents; use function Safe\scandir; +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class CheckSafeFunctionUsageSniff implements Sniff { /** @var array */ diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php index b218d1a..c2c5246 100644 --- a/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php +++ b/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php @@ -20,7 +20,6 @@ use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\JSStyleLint\JSStyleLintCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCodeSniffer\PHPCodeSnifferCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCopyPasteDetector\PHPCopyPasteDetectorCommand; -use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPMessDetector\PHPMessDetectorCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPParallelLint\PHPParallelLintCommand; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPStan\PHPStanCommand; use Zooroyal\CodingStandard\Tests\Tools\SubjectFactory; diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniffTest.php index 548ee83..a27a802 100644 --- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniffTest.php +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniffTest.php @@ -241,7 +241,7 @@ public function registerReturnsExpectedTokens(): void /** * @test */ - public function processWithConfiguredMaximum() + public function processWithConfiguredMaximum(): void { $mockedFile = mock(File::class); $forgedStackPointer = 0; @@ -262,7 +262,7 @@ public function processWithConfiguredMaximum() /** * @test */ - public function processWithConfiguredMinimum() + public function processWithConfiguredMinimum(): void { $mockedFile = mock(File::class); $forgedStackPointer = 0; diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php index d47cb5d..49b851a 100644 --- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php @@ -94,7 +94,7 @@ public function notFoundSafeVersionLibraryThrowsError(): void $mockedFilesystem->expects()->exists('/foo/bar/vendor/thecodingmachine/safe/generated/8.4/')->andReturn(false); try { - $subject = new CheckSafeFunctionUsageSniff(); + new CheckSafeFunctionUsageSniff(); } catch (DirException $exception) { self::assertSame( 'Path "/foo/bar/vendor/thecodingmachine/safe/generated/8.4/" does not exist! ' From a308c2f10e536db88497269188a8e8b6014e5014 Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Thu, 27 Mar 2025 15:43:54 +0100 Subject: [PATCH 27/32] Sniff must not fail in constructor --- composer.json | 24 +++++----- .../Safe/CheckSafeFunctionUsageSniff.php | 8 ++-- tests/System/Complete/GlobalSystemTest.php | 1 - .../Safe/CheckSafeFunctionUsageSniffTest.php | 46 +++++-------------- 4 files changed, 27 insertions(+), 52 deletions(-) diff --git a/composer.json b/composer.json index e57c327..91a136e 100644 --- a/composer.json +++ b/composer.json @@ -27,30 +27,30 @@ "ext-json": "*", "ext-xml": "*", "composer-runtime-api": "^2.0", - "bamarni/composer-bin-plugin": "^1.8", - "composer/semver": "^3.4", + "bamarni/composer-bin-plugin": "^1.8.2", + "composer/semver": "^3.4.3", "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", - "nette/neon": "^3.3", - "nette/utils": "^4.0", + "nette/neon": "^3.4.4", + "nette/utils": "^4.0.5", "nikic/php-parser": "^5.4.0", "php-di/php-di": "^7.0.1", - "slevomat/coding-standard": "^8.10.0", - "squizlabs/php_codesniffer": "^3.9.0", + "slevomat/coding-standard": "^8.16.1", + "squizlabs/php_codesniffer": "^3.12.0", "symfony/console": " ^7.2.1", "symfony/event-dispatcher": "^7.2.0", "symfony/filesystem": " ^7.2.0", - "symfony/process": " ^7.2.0", - "thecodingmachine/safe": "^3.0.1", + "symfony/process": " ^7.2.4", + "thecodingmachine/safe": "^3.0.2", "webmozart/path-util": "^2.3" }, "require-dev": { "amphp/amp": "^v2.6.2", - "amphp/phpunit-util": "^2.0.0", - "amphp/process": "^v1.1.4", + "amphp/phpunit-util": "^2.0.1", + "amphp/process": "^v1.1.9", "brianium/paratest": "^v6.11.1", - "infection/infection": ">=0.29.12", + "infection/infection": ">=0.29.14", "mockery/mockery": "1.6.11", - "phpunit/phpunit": "^9.6.16", + "phpunit/phpunit": "^9.6.22", "roave/security-advisories": "dev-latest", "sebastianknott/hamcrest-object-accessor": "^3.0.0" }, diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php index a220516..f9229ef 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php @@ -41,12 +41,12 @@ public function __construct() $fileSystem = $container->get(Filesystem::class); $path = $environment->getRootDirectory()->getRealPath() . '/vendor/thecodingmachine/safe/generated/' . $major . '.' . $minor . '/'; + if (!$fileSystem->exists($path)) { - throw new DirException( - sprintf('Path "%s" does not exist! Did you install thecodingmachine/safe >= 3', $path), - 1742901391 - ); + $this->functionNames = []; + return; } + try { // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged $filesUnfiltered = @scandir($path); diff --git a/tests/System/Complete/GlobalSystemTest.php b/tests/System/Complete/GlobalSystemTest.php index fbbf620..46c31e2 100644 --- a/tests/System/Complete/GlobalSystemTest.php +++ b/tests/System/Complete/GlobalSystemTest.php @@ -111,7 +111,6 @@ private function runTools(string $environmentDirectory, bool $errorsAreGood = fa { $tools = [ 'sca:sniff', - 'sca:mess', 'sca:para', 'sca:copy', 'sca:stan', diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php index 49b851a..69ee97b 100644 --- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php @@ -11,7 +11,6 @@ use PHP_CodeSniffer\Sniffs\Sniff; use PHPUnit\Framework\TestCase; use RuntimeException; -use Safe\Exceptions\DirException; use Symfony\Component\Filesystem\Filesystem; use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; @@ -41,8 +40,9 @@ public function constructTheSniff(): void * * @runInSeparateProcess * @preserveGlobalState disabled + * @dataProvider notFoundSafeLibrarySkipsProcessDataProvider */ - public function notFoundSafeLibrarySkipsProcess(): void + public function notFoundSafeLibrarySkipsProcess(string $environmentPath, bool $dirExists): void { $mockedContainerFactory = Mockery::mock('overload:' . ContainerFactory::class); $mockedContainer = Mockery::mock(Container::class); @@ -55,8 +55,9 @@ public function notFoundSafeLibrarySkipsProcess(): void $mockedContainer->expects()->get(Environment::class)->andReturn($mockedEnvironment); $mockedContainer->expects()->get(ComposerInterpreter::class)->andReturn($mockedComposerInterpreter); $mockedContainer->expects()->get(Filesystem::class)->andReturn($mockedFilesystem); - $mockedEnvironment->shouldReceive('getRootDirectory->getRealPath')->andReturn('/foo/bar'); - $mockedFilesystem->expects()->exists('/foo/bar/vendor/thecodingmachine/safe/generated/8.4/')->andReturn(true); + $mockedEnvironment->shouldReceive('getRootDirectory->getRealPath')->andReturn($environmentPath); + $mockedFilesystem->expects()->exists($environmentPath . '/vendor/thecodingmachine/safe/generated/8.4/') + ->andReturn($dirExists); $mockedComposerInterpreter->expects()->getMinimalViablePhpVersion()->andReturn('8.4.3'); @@ -71,38 +72,13 @@ public function notFoundSafeLibrarySkipsProcess(): void $subject->process($mockedFile, 0); } - /** - * @test - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function notFoundSafeVersionLibraryThrowsError(): void + /** @return array> */ + public function notFoundSafeLibrarySkipsProcessDataProvider(): array { - $mockedContainerFactory = Mockery::mock('overload:' . ContainerFactory::class); - $mockedContainer = Mockery::mock(Container::class); - $mockedEnvironment = Mockery::mock(Environment::class); - $mockedComposerInterpreter = Mockery::mock(ComposerInterpreter::class); - $mockedFilesystem = mock(Filesystem::class); - - $mockedContainerFactory->expects()->getContainerInstance()->andReturn($mockedContainer); - $mockedContainer->expects()->get(Environment::class)->andReturn($mockedEnvironment); - $mockedContainer->expects()->get(ComposerInterpreter::class)->andReturn($mockedComposerInterpreter); - $mockedComposerInterpreter->expects()->getMinimalViablePhpVersion()->andReturn('8.4.3'); - $mockedContainer->expects()->get(Filesystem::class)->andReturn($mockedFilesystem); - $mockedEnvironment->shouldReceive('getRootDirectory->getRealPath')->andReturn('/foo/bar'); - $mockedFilesystem->expects()->exists('/foo/bar/vendor/thecodingmachine/safe/generated/8.4/')->andReturn(false); - - try { - new CheckSafeFunctionUsageSniff(); - } catch (DirException $exception) { - self::assertSame( - 'Path "/foo/bar/vendor/thecodingmachine/safe/generated/8.4/" does not exist! ' - . 'Did you install thecodingmachine/safe >= 3', - $exception->getMessage() - ); - self::assertSame(1742901391, $exception->getCode()); - } + return [ + 'no Path' => ['environmentPath' => '/foo/bar', 'dirExists' => true], + 'scandir empty' => ['environmentPath' => __DIR__, 'dirExists' => false], + ]; } /** From e359cfb2dff84a27eafae56275ea91ce7100fb41 Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Thu, 27 Mar 2025 17:03:25 +0100 Subject: [PATCH 28/32] Letting users know what went wront with safe --- .../ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php | 2 +- .../ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php | 5 ++++- .../ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php index f9229ef..c33418c 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php @@ -105,7 +105,7 @@ public function process(File $phpcsFile, $stackPtr): void { if ($this->functionNames === []) { throw new AssertionException( - 'No function names found! Did you forget to install thecodingmachine/Safe?', + 'No function names found! Did you forget to install thecodingmachine/Safe ^v3?', 1684240278, ); } diff --git a/tests/System/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/System/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php index dffd97c..3282db4 100644 --- a/tests/System/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php +++ b/tests/System/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php @@ -61,7 +61,10 @@ public function nagIfSafeIsNotInstalled(): void $output = $processCodingStandard->getOutput(); self::assertMatchesRegularExpression('/No.*function.*names.*found!/ms', $output); - self::assertMatchesRegularExpression('/Did.*you.*forget.*to.*install.*thecodingmachine\/Safe\?/ms', $output); + self::assertMatchesRegularExpression( + '/Did.*you.*forget.*to.*install.*thecodingmachine\/Safe \^v3\?/ms', + $output + ); } private function prepareInstallationDirectory(): string diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php index 69ee97b..c2045d2 100644 --- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php @@ -63,7 +63,7 @@ public function notFoundSafeLibrarySkipsProcess(string $environmentPath, bool $d $this->expectExceptionObject( new RuntimeException( - 'No function names found! Did you forget to install thecodingmachine/Safe?', + 'No function names found! Did you forget to install thecodingmachine/Safe ^v3?', 1684240278, ), ); From 3990552ba32b3298551cfe6ba8104977d57eec01 Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Fri, 28 Mar 2025 14:49:15 +0100 Subject: [PATCH 29/32] Kill the CheckSafe mutants --- README.md | 1 - composer.json | 1 + doc/howto/HowToAddANewTool.md | 33 ++- infection.json.dist | 4 +- .../Safe/CheckSafeFunctionUsageSniff.php | 6 +- .../Safe/CheckSafeFunctionUsageSniffTest.php | 265 +++++++++++++++++- 6 files changed, 286 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index fb8582b..4fdd65e 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ Coding Standard. It incorporates * [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer) and its configuration -* [PHP Mess Detector](https://github.com/phpmd/phpmd) and its configuration * [PHP Copy Paste Detector](https://github.com/sebastianbergmann/phpcpd) * [PHP-Parallel-Lint](https://github.com/JakubOnderka/PHP-Parallel-Lint) * [PHPStan - PHP Static Analysis Tool](https://github.com/phpstan/phpstan) diff --git a/composer.json b/composer.json index 91a136e..39936c1 100644 --- a/composer.json +++ b/composer.json @@ -49,6 +49,7 @@ "amphp/process": "^v1.1.9", "brianium/paratest": "^v6.11.1", "infection/infection": ">=0.29.14", + "mikey179/vfsstream": "^1.6", "mockery/mockery": "1.6.11", "phpunit/phpunit": "^9.6.22", "roave/security-advisories": "dev-latest", diff --git a/doc/howto/HowToAddANewTool.md b/doc/howto/HowToAddANewTool.md index 81b3199..0c2764e 100644 --- a/doc/howto/HowToAddANewTool.md +++ b/doc/howto/HowToAddANewTool.md @@ -4,7 +4,7 @@ First of all you need to gather some information about your new tool. -1. Is the tool able to only work on files you provide by a command-line +1. Is the tool able to only work on files you provide by a command-line parameter? \ For example Parallel Lint is able to only work on certain files. ```bash @@ -20,7 +20,7 @@ First of all you need to gather some information about your new tool. Let's say you want to add your new tool 'SuperCoolTool' to the coding-standard -1. Create a new namespace +1. Create a new namespace `Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\SuperCoolTool`. 2. Create two new Classes in your new namespace: `SuperCoolToolCommand` and `TerminalCommand`. 3. Register your new command. @@ -29,7 +29,7 @@ The next paragraphs will guid you through that process. ### Implement SuperCoolToolCommand -This class stores some vital information about the SuperCoolTool. The +This class stores some vital information about the SuperCoolTool. The coding-standard will use this information to integrate your tool in its cli. For now it's best to just have a look at this example implementation. @@ -44,10 +44,10 @@ your tool you want to expose to the user. We are going to assume a FixingToolCommand for our SuperCoolTool - its SuperCool after all! ```php -class SuperCoolToolCommand extends FixingToolCommand +class SuperCoolToolCommand extends FixingToolCommand { // What file makes your tool ignore a directory - protected string $exclusionListToken = '.dontBeSuperCool'; + protected string $exclusionListToken = '.dontBeSuperCool'; // Do you only want to check for certain file Types? If not leave empty protected array $allowedFileEndings = ['sc']; @@ -86,7 +86,7 @@ class SuperCoolToolCommand extends FixingToolCommand */ public function injectDependenciesCommand(Container $container): void { - // Create an instance of your TerminalCommand and store it in this property. + // Create an instance of your TerminalCommand and store it in this property. // You may use the container like so but it really doesn't matter as long as // an instance of your TerminalCommand will be stored in this property $this->terminalCommand = $container->make(TerminalCommand::class); @@ -97,9 +97,9 @@ class SuperCoolToolCommand extends FixingToolCommand ### Implement your TerminalCommand -The coding-standard will inject your TerminalCommand with important +The coding-standard will inject your TerminalCommand with important information about the user input and context of the system, but you have to tell it what information you would like to get. For this reason we are using interfaces. \ -In case of your SuperCoolTool we will get information about the files it +In case of your SuperCoolTool we will get information about the files it should be checking and the fixing mode. Let's see... @@ -110,19 +110,19 @@ Let's see... // It is a FixingTerminalCommand and TargetableTerminalCommand class TerminalCommand extends AbstractTerminalCommand implements FixingTerminalCommand, TargetableTerminalCommand { - // So you don't need to hassle with setters and such, simply use the + // So you don't need to hassle with setters and such, simply use the // provided traits. The coding-standard provides a trait for every - // TerminalCommand interface. + // TerminalCommand interface. use TargetableTrait, FixingTrait; - // The TargetableTrait will create a field named $targetedFiles. The - // FixingTrait will create a field named $fixingMode. They will be set + // The TargetableTrait will create a field named $targetedFiles. The + // FixingTrait will create a field named $fixingMode. They will be set // by higher magic. - // For more information about available traits and interfaces you may + // For more information about available traits and interfaces you may // need to read their respectivsource code - + /** - * This method must implement the compilation of the command. Technically it has + * This method must implement the compilation of the command. Technically it has * one shot in setting the protected fields $command and $commandParts. */ protected function compile(): void @@ -159,7 +159,6 @@ class ApplicationFactory PHPCodeSnifferCommand::class, PHPCopyPasteDetectorCommand::class, PHPParallelLintCommand::class, - PHPMessDetectorCommand::class, PHPStanCommand::class, JSESLintCommand::class, JSStyleLintCommand::class, @@ -171,7 +170,7 @@ class ApplicationFactory ``` BAM! It's done! Now you can call your tool from command-line -```bash +```bash src/bin/coding-standard sca:supercool # from your dev environment vendor/bin/coding-standard sca:supercool # if installed as a library ``` diff --git a/infection.json.dist b/infection.json.dist index e07aa18..88f1029 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -1,7 +1,7 @@ { "timeout": 20, - "minMsi": 87, - "minCoveredMsi": 95, + "minMsi": 91, + "minCoveredMsi": 94, "source": { "directories": [ "src\/main\/php" diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php index c33418c..b09d1cb 100644 --- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php +++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php @@ -111,12 +111,12 @@ public function process(File $phpcsFile, $stackPtr): void } $tokens = $phpcsFile->getTokens(); - $functionName = strtolower(ltrim($tokens[$stackPtr]['content'], '\\')); + $functionName = strtolower($tokens[$stackPtr]['content']); try { $this->assertNextTokenParenthesisOpener($phpcsFile, $stackPtr); $this->assertGlobalFunctionCall($phpcsFile, $stackPtr); - $this->assertFunctionProvidedBySafe($tokens[$stackPtr]['content']); + $this->assertFunctionProvidedBySafe($functionName); $this->assertFunctionUnused($phpcsFile, $functionName); } catch (AssertionException) { // If this is the case we found no Safe function. Continue... @@ -140,7 +140,7 @@ private function assertGlobalFunctionCall(File $phpcsFile, int $stackPtr): void if ( in_array( $phpcsFile->getTokens()[$previousPointer]['code'], - [T_OBJECT_OPERATOR, T_DOUBLE_COLON, T_FUNCTION], + [T_OBJECT_OPERATOR, T_DOUBLE_COLON, T_FUNCTION, T_NEW], true, ) ) { diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php index c2045d2..7d07a5a 100644 --- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php +++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php @@ -6,19 +6,35 @@ use DI\Container; use Mockery; +use Mockery\MockInterface; +use org\bovigo\vfs\vfsStream; +use org\bovigo\vfs\vfsStreamDirectory; use Override; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; +use PhpParser\NodeFinder; +use PhpParser\Parser; +use PhpParser\ParserFactory; +use PhpParser\PhpVersion; use PHPUnit\Framework\TestCase; use RuntimeException; +use SlevomatCodingStandard\Helpers\TokenHelper; +use SlevomatCodingStandard\Helpers\UseStatement; +use SlevomatCodingStandard\Helpers\UseStatementHelper; use Symfony\Component\Filesystem\Filesystem; use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory; use Zooroyal\CodingStandard\CommandLine\Environment\Environment; use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\ComposerInterpreter; use Zooroyal\CodingStandard\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\Safe\CheckSafeFunctionUsageSniff; +// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements class CheckSafeFunctionUsageSniffTest extends TestCase { + private const string SAFE_VENDOR_PATH = '/vendor/thecodingmachine/safe/generated/8.4/'; + + private vfsStreamDirectory $vfsRootDirectory; + private vfsStreamDirectory $vfsSafeDirectory; + #[Override] protected function tearDown(): void { @@ -26,6 +42,14 @@ protected function tearDown(): void parent::tearDown(); } + protected function setUp(): void + { + parent::setUp(); + $this->vfsRootDirectory = vfsStream::setup('checkSafe'); + $this->vfsSafeDirectory = vfsStream::newDirectory(self::SAFE_VENDOR_PATH, 0777); + $this->vfsRootDirectory->addChild($this->vfsSafeDirectory); + } + /** * @test */ @@ -35,6 +59,45 @@ public function constructTheSniff(): void self::assertInstanceOf(Sniff::class, $subject); } + private function prepareMocksForAssertNextTokenParenthesisOpener( + MockInterface&File $mockedFile, + int $forgedPointer, + ): MockInterface&TokenHelper { + // Mocks for assertNextTokenParenthesisOpener + $mockedTokenHelper = Mockery::mock('overload:' . TokenHelper::class); + $mockedTokenHelper->expects()->findNextEffective($mockedFile, $forgedPointer + 1) + ->andReturn($forgedPointer + 1); + return $mockedTokenHelper; + } + + private function prepareMocksForAssertFunctionUnused(MockInterface&File $mockedFile): void + { + // Mocks for assertFunctionUnused + $mockedUseStatementFunctionUninteresting = Mockery::mock(UseStatement::class); + $mockedUseStatement = Mockery::mock(UseStatement::class); + $forgedUseStatementResults = [ + 17 => [ + 'overwrite' => $mockedUseStatementFunctionUninteresting, + 'sniff' => $mockedUseStatement, + ], + ]; + $mockedUseStatementHelper = Mockery::mock('overload:' . UseStatementHelper::class); + $mockedUseStatementHelper->expects()->getFileUseStatements($mockedFile)->andReturn($forgedUseStatementResults); + $mockedUseStatementFunctionUninteresting->expects()->getType()->andReturn('function'); + $mockedUseStatement->expects()->getType()->andReturn('no function'); + $mockedUseStatementFunctionUninteresting->expects()->getNameAsReferencedInFile()->andReturn('argh'); + } + + private function prepareMocksForAssertGlobalFunctionCall( + MockInterface&TokenHelper $mockedTokenHelper, + MockInterface&File $mockedFile, + int $forgedPointer, + ): void { + // Mocks for assertGlobalFunctionCall + $mockedTokenHelper->expects()->findPreviousEffective($mockedFile, $forgedPointer - 1) + ->andReturn($forgedPointer - 1); + } + /** * @test * @@ -56,7 +119,7 @@ public function notFoundSafeLibrarySkipsProcess(string $environmentPath, bool $d $mockedContainer->expects()->get(ComposerInterpreter::class)->andReturn($mockedComposerInterpreter); $mockedContainer->expects()->get(Filesystem::class)->andReturn($mockedFilesystem); $mockedEnvironment->shouldReceive('getRootDirectory->getRealPath')->andReturn($environmentPath); - $mockedFilesystem->expects()->exists($environmentPath . '/vendor/thecodingmachine/safe/generated/8.4/') + $mockedFilesystem->expects()->exists($environmentPath . self::SAFE_VENDOR_PATH) ->andReturn($dirExists); $mockedComposerInterpreter->expects()->getMinimalViablePhpVersion()->andReturn('8.4.3'); @@ -81,6 +144,173 @@ public function notFoundSafeLibrarySkipsProcessDataProvider(): array ]; } + /** + * @test + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function processAddsError(): void + { + $forgedPointer = 100; + $forgedSafeFunctionName = 'foo'; + $mockedFile = $this->prepareMocksForConstruction(['foo.php' => 'allows()->getTokens()->andReturn( + [ + $forgedPointer - 1 => ['code' => T_WHITESPACE], + $forgedPointer => ['code' => T_STRING, 'content' => 'Foo'], + $forgedPointer + 1 => ['code' => T_OPEN_PARENTHESIS], + ], + ); + $mockedTokenHelper = $this->prepareMocksForAssertNextTokenParenthesisOpener($mockedFile, $forgedPointer); + $this->prepareMocksForAssertGlobalFunctionCall($mockedTokenHelper, $mockedFile, $forgedPointer); + $this->prepareMocksForAssertFunctionUnused($mockedFile); + + // Finish with the key assertion + + $mockedFile->expects()->addError( + 'Function \'' . $forgedSafeFunctionName + . '\' is not imported from Safe! Add \'use function Safe\foo;\' to your uses.', + $forgedPointer, + 'FunctionNotImported' + ); + + $subject = new CheckSafeFunctionUsageSniff(); + $subject->process($mockedFile, $forgedPointer); + } + + /** + * @test + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function processAddsNoErrorBecauseOfParenthesisCheck(): void + { + $forgedPointer = 100; + $forgedSafeFunctionName = 'foo'; + $mockedFile = $this->prepareMocksForConstruction(['foo.php' => 'allows()->getTokens()->andReturn( + [ + $forgedPointer - 1 => ['code' => T_OBJECT_OPERATOR], + $forgedPointer => ['code' => T_STRING, 'content' => 'Foo'], + $forgedPointer + 1 => ['code' => T_STRING], + ], + ); + + $mockedTokenHelper = Mockery::mock('overload:' . TokenHelper::class); + $mockedTokenHelper->expects()->findNextEffective($mockedFile, $forgedPointer + 1) + ->andReturn($forgedPointer + 1); + + $mockedFile->shouldNotReceive('addError'); + + $subject = new CheckSafeFunctionUsageSniff(); + $subject->process($mockedFile, $forgedPointer); + } + + /** + * @test + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function processAddsNoErrorBecauseGlobalFunction(): void + { + $forgedPointer = 100; + $forgedSafeFunctionName = 'foo'; + $mockedFile = $this->prepareMocksForConstruction(['foo.php' => 'allows()->getTokens()->andReturn( + [ + $forgedPointer - 1 => ['code' => T_FUNCTION], + $forgedPointer => ['code' => T_STRING, 'content' => 'Foo'], + $forgedPointer + 1 => ['code' => T_OPEN_PARENTHESIS], + ], + ); + + $mockedTokenHelper = $this->prepareMocksForAssertNextTokenParenthesisOpener($mockedFile, $forgedPointer); + $mockedTokenHelper->expects()->findPreviousEffective($mockedFile, $forgedPointer - 1) + ->andReturn($forgedPointer - 1); + + $mockedFile->shouldNotReceive('addError'); + + $subject = new CheckSafeFunctionUsageSniff(); + $subject->process($mockedFile, $forgedPointer); + } + + /** + * @test + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function processAddsNoErrorBecauseNotSafeFunction(): void + { + $forgedPointer = 100; + $forgedSafeFunctionName = 'foo'; + $mockedFile = $this->prepareMocksForConstruction(['foo.php' => 'allows()->getTokens()->andReturn( + [ + $forgedPointer - 1 => ['code' => T_WHITESPACE], + $forgedPointer => ['code' => T_STRING, 'content' => 'Woo'], + $forgedPointer + 1 => ['code' => T_OPEN_PARENTHESIS], + ], + ); + $mockedTokenHelper = $this->prepareMocksForAssertNextTokenParenthesisOpener($mockedFile, $forgedPointer); + $this->prepareMocksForAssertGlobalFunctionCall($mockedTokenHelper, $mockedFile, $forgedPointer); + + // Finish with the key assertion + + $mockedFile->shouldNotReceive('addError'); + + $subject = new CheckSafeFunctionUsageSniff(); + $subject->process($mockedFile, $forgedPointer); + } + + /** + * @test + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function processAddsNoErrorBecauseFunctionUsed(): void + { + $forgedPointer = 100; + $forgedSafeFunctionName = 'foo'; + $mockedFile = $this->prepareMocksForConstruction(['foo.php' => 'allows()->getTokens()->andReturn( + [ + $forgedPointer - 1 => ['code' => T_WHITESPACE], + $forgedPointer => ['code' => T_STRING, 'content' => 'Foo'], + $forgedPointer + 1 => ['code' => T_OPEN_PARENTHESIS], + ], + ); + $mockedTokenHelper = $this->prepareMocksForAssertNextTokenParenthesisOpener($mockedFile, $forgedPointer); + $this->prepareMocksForAssertGlobalFunctionCall($mockedTokenHelper, $mockedFile, $forgedPointer); + + $mockedUseStatement = Mockery::mock(UseStatement::class); + $forgedUseStatementResults = [ + 17 => [ + 'foo' => $mockedUseStatement, + ], + ]; + $mockedUseStatementHelper = Mockery::mock('overload:' . UseStatementHelper::class); + $mockedUseStatementHelper->expects()->getFileUseStatements($mockedFile)->andReturn($forgedUseStatementResults); + $mockedUseStatement->expects()->getType()->andReturn('function'); + $mockedUseStatement->expects()->getNameAsReferencedInFile()->andReturn($forgedSafeFunctionName); + + // Finish with the key assertion + + $mockedFile->shouldNotReceive('addError'); + + $subject = new CheckSafeFunctionUsageSniff(); + $subject->process($mockedFile, $forgedPointer); + } + /** * @test */ @@ -91,4 +321,37 @@ public function registerReturnsCorrectTokenArray(): void self::assertSame([T_STRING], $result); } + + /** @param array $safeFiles */ + private function prepareMocksForConstruction(array $safeFiles): MockInterface&File + { + $environmentPath = vfsStream::url('checkSafe'); + + $mockedContainerFactory = Mockery::mock('overload:' . ContainerFactory::class); + $mockedContainer = Mockery::mock(Container::class); + $mockedEnvironment = Mockery::mock(Environment::class); + $mockedFile = Mockery::mock(File::class); + $mockedComposerInterpreter = Mockery::mock(ComposerInterpreter::class); + $mockedFilesystem = mock(Filesystem::class); + + $mockedContainerFactory->expects()->getContainerInstance()->andReturn($mockedContainer); + $mockedComposerInterpreter->expects()->getMinimalViablePhpVersion()->andReturn('8.4.3'); + $mockedContainer->expects()->get(Environment::class)->andReturn($mockedEnvironment); + $mockedContainer->expects()->get(ComposerInterpreter::class)->andReturn($mockedComposerInterpreter); + $mockedContainer->expects()->get(Filesystem::class)->andReturn($mockedFilesystem); + $mockedEnvironment->shouldReceive('getRootDirectory->getRealPath')->andReturn($environmentPath); + $mockedFilesystem->expects()->exists($environmentPath . self::SAFE_VENDOR_PATH) + ->andReturn(true); + + vfsStream::create( + ['vendor' => ['thecodingmachine' => ['safe' => ['generated' => ['8.4' => $safeFiles]]]]], + $this->vfsRootDirectory + ); + + $mockedContainer->expects()->get(Parser::class) + ->andReturn(new ParserFactory()->createForVersion(PhpVersion::fromString('8.4'))); + $mockedContainer->expects()->get(NodeFinder::class)->andReturn(new NodeFinder()); + + return $mockedFile; + } } From 4550f24252f634482630a50498f1e5a3dc2c3bb6 Mon Sep 17 00:00:00 2001 From: Peter Kuehn Date: Mon, 31 Mar 2025 08:35:19 +0200 Subject: [PATCH 30/32] set required version of mikey179/vfsstream fix to v1.6.12 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 39936c1..f7ea96c 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "amphp/process": "^v1.1.9", "brianium/paratest": "^v6.11.1", "infection/infection": ">=0.29.14", - "mikey179/vfsstream": "^1.6", + "mikey179/vfsstream": "^1.6.12", "mockery/mockery": "1.6.11", "phpunit/phpunit": "^9.6.22", "roave/security-advisories": "dev-latest", From 5e48e9be41daa23cb6c3ff828c5c12e3b171bf42 Mon Sep 17 00:00:00 2001 From: Peter Kuehn Date: Mon, 31 Mar 2025 09:45:18 +0200 Subject: [PATCH 31/32] improove tests --- infection.json.dist | 2 +- .../FindFilesToCheckCommandTest.php | 45 +++++++++++++------ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/infection.json.dist b/infection.json.dist index 88f1029..ed27bea 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -1,6 +1,6 @@ { "timeout": 20, - "minMsi": 91, + "minMsi": 87, "minCoveredMsi": 94, "source": { "directories": [ diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php index c710d80..cf1bdd0 100644 --- a/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php +++ b/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php @@ -38,6 +38,37 @@ class FindFilesToCheckCommandTest extends TestCase private string $expectedResult1 = 'phpunit.xml.dist'; private string $expectedResult2 = 'composer.json'; + private static function assertSetDefinitionParams(InputDefinition $value): bool + { + MatcherAssert::assertThat($value, H::anInstanceOf(InputDefinition::class)); + $options = $value->getOptions(); + MatcherAssert::assertThat( + $options, + H::allOf( + H::arrayWithSize(6), + H::everyItem( + H::anInstanceOf(InputOption::class), + ), + ), + ); + MatcherAssert::assertThat( + $value->getOption('target')->getDescription(), + H::equalTo('Finds files which have changed since the current branch parted from the target branch ' + . 'only. The Value has to be a commit-ish.') + ); + MatcherAssert::assertThat( + $value->getOption('auto-target')->getDescription(), + H::equalTo('Finds Files which have changed since the current branch parted from the parent branch ' + . 'only. It tries to find the parent branch by automagic.') + ); + MatcherAssert::assertThat( + $value->getOption('allowed-file-endings')->getDescription(), + H::equalTo('Only list files with appropriate file endings. For example .php for PHP-Files. ' + . 'You may give multiple') + ); + return true; + } + #[Override] protected function setUp(): void { @@ -89,19 +120,7 @@ public function configure(): void ->with( Mockery::on( static function ($value): bool { - MatcherAssert::assertThat($value, H::anInstanceOf(InputDefinition::class)); - /** @var InputDefinition $value */ - $options = $value->getOptions(); - MatcherAssert::assertThat( - $options, - H::allOf( - H::arrayWithSize(6), - H::everyItem( - H::anInstanceOf(InputOption::class), - ), - ), - ); - return true; + return self::assertSetDefinitionParams($value); }, ), )->andReturnSelf(); From f960af34bea769f85f275c79d90a286c7ce9deb8 Mon Sep 17 00:00:00 2001 From: Sebastian Knott Date: Mon, 31 Mar 2025 12:01:32 +0200 Subject: [PATCH 32/32] Piun the execution order to get more comparable infection results --- infection.json.dist | 2 +- phpunit.xml.dist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/infection.json.dist b/infection.json.dist index ed27bea..8947edc 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -1,6 +1,6 @@ { "timeout": 20, - "minMsi": 87, + "minMsi": 86, "minCoveredMsi": 94, "source": { "directories": [ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7d0d690..8858051 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,7 +3,7 @@ beStrictAboutTestsThatDoNotTestAnything="false" colors="true" bootstrap="vendor/autoload.php" enforceTimeLimit="true" - executionOrder="random" + executionOrder="depends" resolveDependencies="true" stopOnRisky="true" timeoutForSmallTests="2"