From dd7e1cd5717c4e502aad485bdb2a5b55897034e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sat, 30 Nov 2024 18:10:19 +0100 Subject: [PATCH] Enhancement: Add rule error identifiers --- .github/workflows/integrate.yaml | 7 +- CHANGELOG.md | 5 + Makefile | 9 +- src/Classes/FinalRule.php | 3 +- src/Classes/NoExtendsRule.php | 5 +- .../Framework/TestCaseWithSuffixRule.php | 3 +- .../NoNullableReturnTypeDeclarationRule.php | 3 +- .../NoParameterWithNullDefaultValueRule.php | 3 +- ...rameterWithNullableTypeDeclarationRule.php | 3 +- src/ErrorIdentifier.php | 112 +++++++++++++++ src/Expressions/NoCompactRule.php | 3 +- src/Expressions/NoErrorSuppressionRule.php | 3 +- src/Expressions/NoEvalRule.php | 3 +- src/Expressions/NoIssetRule.php | 3 +- src/Files/DeclareStrictTypesRule.php | 3 +- .../NoNullableReturnTypeDeclarationRule.php | 3 +- .../NoParameterWithNullDefaultValueRule.php | 3 +- ...rameterWithNullableTypeDeclarationRule.php | 3 +- src/Methods/FinalInAbstractClassRule.php | 3 +- ...nstructorParameterWithDefaultValueRule.php | 3 +- .../NoNullableReturnTypeDeclarationRule.php | 5 +- ...ameterWithContainerTypeDeclarationRule.php | 5 +- .../NoParameterWithNullDefaultValueRule.php | 9 +- ...rameterWithNullableTypeDeclarationRule.php | 13 +- src/Methods/PrivateInFinalClassRule.php | 3 +- src/Statements/NoSwitchRule.php | 3 +- test/Integration/Classes/FinalRuleTest.php | 2 + ...inalRuleWithAbstractClassesAllowedTest.php | 2 + .../Classes/FinalRuleWithAttributesTest.php | 2 + .../FinalRuleWithExcludedClassNamesTest.php | 2 + .../Integration/Classes/NoExtendsRuleTest.php | 2 + ...RuleWithClassesAllowedToBeExtendedTest.php | 2 + .../Framework/TestCaseWithSuffixRuleTest.php | 2 + ...oNullableReturnTypeDeclarationRuleTest.php | 2 + ...oParameterWithNullDefaultValueRuleTest.php | 2 + ...terWithNullableTypeDeclarationRuleTest.php | 2 + .../Expressions/NoCompactRuleTest.php | 2 + .../NoErrorSuppressionRuleTest.php | 2 + .../Expressions/NoEvalRuleTest.php | 2 + .../Expressions/NoIssetRuleTest.php | 2 + .../Files/DeclareStrictTypesRuleTest.php | 2 + ...oNullableReturnTypeDeclarationRuleTest.php | 2 + ...oParameterWithNullDefaultValueRuleTest.php | 2 + ...terWithNullableTypeDeclarationRuleTest.php | 2 + .../Methods/FinalInAbstractClassRuleTest.php | 2 + ...uctorParameterWithDefaultValueRuleTest.php | 2 + ...oNullableReturnTypeDeclarationRuleTest.php | 2 + ...erWithContainerTypeDeclarationRuleTest.php | 2 + ...oParameterWithNullDefaultValueRuleTest.php | 2 + ...terWithNullableTypeDeclarationRuleTest.php | 2 + .../Methods/PrivateInFinalClassRuleTest.php | 2 + .../Statements/NoSwitchRuleTest.php | 2 + test/Unit/ErrorIdentifierTest.php | 133 ++++++++++++++++++ test/{Integration => }/phpunit.xml | 15 +- 54 files changed, 376 insertions(+), 45 deletions(-) create mode 100644 src/ErrorIdentifier.php create mode 100644 test/Unit/ErrorIdentifierTest.php rename test/{Integration => }/phpunit.xml (62%) diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index 0724fa93..f76c3b95 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -62,7 +62,7 @@ jobs: - name: "Collect code coverage with Xdebug and phpunit/phpunit" env: XDEBUG_MODE: "coverage" - run: "vendor/bin/phpunit --colors=always --configuration=test/Integration/phpunit.xml --coverage-clover=.build/phpunit/logs/clover.xml" + run: "vendor/bin/phpunit --colors=always --configuration=test/phpunit.xml --coverage-clover=.build/phpunit/logs/clover.xml" - name: "Send code coverage report to codecov.io" uses: "codecov/codecov-action@v5.0.7" @@ -358,5 +358,8 @@ jobs: with: dependencies: "${{ matrix.dependencies }}" + - name: "Run unit tests with phpunit/phpunit" + run: "vendor/bin/phpunit --colors=always --configuration=test/phpunit.xml --testsuite=unit" + - name: "Run integration tests with phpunit/phpunit" - run: "vendor/bin/phpunit --colors=always --configuration=test/Integration/phpunit.xml" + run: "vendor/bin/phpunit --colors=always --configuration=test/phpunit.xml --testsuite=integration" diff --git a/CHANGELOG.md b/CHANGELOG.md index e9c2a373..bc7829aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), For a full diff see [`2.4.0...main`][2.4.0...main]. +### Added + +- Added rule error identifiers ([#875]), by [@localheinz] + ## [`2.4.0`][2.4.0] For a full diff see [`2.3.0...2.4.0`][2.3.0...2.4.0]. @@ -523,6 +527,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [#735]: https://github.com/ergebnis/phpstan-rules/pull/735 [#862]: https://github.com/ergebnis/phpstan-rules/pull/862 [#872]: https://github.com/ergebnis/phpstan-rules/pull/872 +[#875]: https://github.com/ergebnis/phpstan-rules/pull/875 [@enumag]: https://github.com/enumag [@ergebnis]: https://github.com/ergebnis diff --git a/Makefile b/Makefile index 13f5a0b9..4467533f 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ it: coding-standards security-analysis static-code-analysis tests ## Runs the coding-standards, security-analysis, static-code-analysis, and tests targets .PHONY: code-coverage -code-coverage: vendor ## Collects coverage from running integration tests with phpunit/phpunit - vendor/bin/phpunit --configuration=test/Integration/phpunit.xml --coverage-text +code-coverage: vendor ## Collects coverage from running unit and integration tests with phpunit/phpunit + vendor/bin/phpunit --configuration=test/phpunit.xml --coverage-text .PHONY: coding-standards coding-standards: vendor ## Lints YAML files with yamllint, normalizes composer.json with ergebnis/composer-normalize, and fixes code style issues with friendsofphp/php-cs-fixer @@ -39,8 +39,9 @@ static-code-analysis-baseline: vendor ## Generates a baseline for static code an vendor/bin/phpstan --allow-empty-baseline --configuration=phpstan.neon --generate-baseline=phpstan-baseline.neon --memory-limit=-1 .PHONY: tests -tests: vendor ## Runs integration tests with phpunit/phpunit - vendor/bin/phpunit --configuration=test/Integration/phpunit.xml +tests: vendor ## Runs unit and integration tests with phpunit/phpunit + vendor/bin/phpunit --configuration=test/phpunit.xml --testsuite=unit + vendor/bin/phpunit --configuration=test/phpunit.xml --testsuite=integration vendor: composer.json composer.lock composer validate --strict diff --git a/src/Classes/FinalRule.php b/src/Classes/FinalRule.php index 22c85c45..ff8dce98 100644 --- a/src/Classes/FinalRule.php +++ b/src/Classes/FinalRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Classes; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Comment; use PhpParser\Node; use PHPStan\Analyser; @@ -107,7 +108,7 @@ public function processNode( )); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::final()->toString())->build(), ]; } diff --git a/src/Classes/NoExtendsRule.php b/src/Classes/NoExtendsRule.php index 77d1cace..45d9aba9 100644 --- a/src/Classes/NoExtendsRule.php +++ b/src/Classes/NoExtendsRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Classes; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Rules; @@ -83,7 +84,7 @@ public function processNode( )); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::noExtends()->toString())->build(), ]; } @@ -94,7 +95,7 @@ public function processNode( )); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::noExtends()->toString())->build(), ]; } } diff --git a/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php b/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php index ff00d4b9..8ea12ecd 100644 --- a/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php +++ b/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Classes\PHPUnit\Framework; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Reflection; @@ -96,7 +97,7 @@ public function processNode( )); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::testCaseWithSuffix()->toString())->build(), ]; } } diff --git a/src/Closures/NoNullableReturnTypeDeclarationRule.php b/src/Closures/NoNullableReturnTypeDeclarationRule.php index 67bfbc0a..f277ee78 100644 --- a/src/Closures/NoNullableReturnTypeDeclarationRule.php +++ b/src/Closures/NoNullableReturnTypeDeclarationRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Closures; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Rules; @@ -47,7 +48,7 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Closure has a nullable return type declaration.'); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString())->build(), ]; } diff --git a/src/Closures/NoParameterWithNullDefaultValueRule.php b/src/Closures/NoParameterWithNullDefaultValueRule.php index 381f928b..74294c1a 100644 --- a/src/Closures/NoParameterWithNullDefaultValueRule.php +++ b/src/Closures/NoParameterWithNullDefaultValueRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Closures; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Rules; @@ -68,7 +69,7 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->build(); + return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString())->build(); }, $params); } } diff --git a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php index 6ba414a4..608c45c6 100644 --- a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Closures; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Rules; @@ -64,7 +65,7 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->build(); + return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString())->build(); }, $params); } diff --git a/src/ErrorIdentifier.php b/src/ErrorIdentifier.php new file mode 100644 index 00000000..2440beb5 --- /dev/null +++ b/src/ErrorIdentifier.php @@ -0,0 +1,112 @@ +value, + ); + } +} diff --git a/src/Expressions/NoCompactRule.php b/src/Expressions/NoCompactRule.php index 6dcc1462..56ff2d6b 100644 --- a/src/Expressions/NoCompactRule.php +++ b/src/Expressions/NoCompactRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Expressions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Rules; @@ -51,7 +52,7 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Function compact() should not be used.'); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::noCompact()->toString())->build(), ]; } } diff --git a/src/Expressions/NoErrorSuppressionRule.php b/src/Expressions/NoErrorSuppressionRule.php index c945f7e0..6bb607a3 100644 --- a/src/Expressions/NoErrorSuppressionRule.php +++ b/src/Expressions/NoErrorSuppressionRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Expressions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Rules; @@ -34,7 +35,7 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Error suppression via "@" should not be used.'); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::noErrorSuppression()->toString())->build(), ]; } } diff --git a/src/Expressions/NoEvalRule.php b/src/Expressions/NoEvalRule.php index 317663dd..2280c08c 100644 --- a/src/Expressions/NoEvalRule.php +++ b/src/Expressions/NoEvalRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Expressions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Rules; @@ -34,7 +35,7 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Language construct eval() should not be used.'); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::noEval()->toString())->build(), ]; } } diff --git a/src/Expressions/NoIssetRule.php b/src/Expressions/NoIssetRule.php index bcba10b5..03708980 100644 --- a/src/Expressions/NoIssetRule.php +++ b/src/Expressions/NoIssetRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Expressions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Rules; @@ -34,7 +35,7 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Language construct isset() should not be used.'); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::noIsset()->toString())->build(), ]; } } diff --git a/src/Files/DeclareStrictTypesRule.php b/src/Files/DeclareStrictTypesRule.php index 399f287c..4e3c207d 100644 --- a/src/Files/DeclareStrictTypesRule.php +++ b/src/Files/DeclareStrictTypesRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Files; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Node\FileNode; @@ -72,7 +73,7 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('File is missing a "declare(strict_types=1)" declaration.'); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::declareStrictTypes()->toString())->build(), ]; } } diff --git a/src/Functions/NoNullableReturnTypeDeclarationRule.php b/src/Functions/NoNullableReturnTypeDeclarationRule.php index e143c51e..f0962382 100644 --- a/src/Functions/NoNullableReturnTypeDeclarationRule.php +++ b/src/Functions/NoNullableReturnTypeDeclarationRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Functions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Rules; @@ -54,7 +55,7 @@ public function processNode( )); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString())->build(), ]; } diff --git a/src/Functions/NoParameterWithNullDefaultValueRule.php b/src/Functions/NoParameterWithNullDefaultValueRule.php index be7b41e4..aec3299f 100644 --- a/src/Functions/NoParameterWithNullDefaultValueRule.php +++ b/src/Functions/NoParameterWithNullDefaultValueRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Functions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Rules; @@ -71,7 +72,7 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->build(); + return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString())->build(); }, $params); } } diff --git a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php index 5182a2f0..a90d6bf9 100644 --- a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Functions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Rules; @@ -67,7 +68,7 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->build(); + return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString())->build(); }, $params); } diff --git a/src/Methods/FinalInAbstractClassRule.php b/src/Methods/FinalInAbstractClassRule.php index e67318e0..5e9bfb9d 100644 --- a/src/Methods/FinalInAbstractClassRule.php +++ b/src/Methods/FinalInAbstractClassRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Reflection; @@ -75,7 +76,7 @@ public function processNode( )); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::finalInAbstractClass()->toString())->build(), ]; } } diff --git a/src/Methods/NoConstructorParameterWithDefaultValueRule.php b/src/Methods/NoConstructorParameterWithDefaultValueRule.php index 0853696e..444ce2ac 100644 --- a/src/Methods/NoConstructorParameterWithDefaultValueRule.php +++ b/src/Methods/NoConstructorParameterWithDefaultValueRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Reflection; @@ -73,7 +74,7 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->build(); + return $ruleErrorBuilder->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString())->build(); }, $params); } diff --git a/src/Methods/NoNullableReturnTypeDeclarationRule.php b/src/Methods/NoNullableReturnTypeDeclarationRule.php index 8f580984..5bcd8613 100644 --- a/src/Methods/NoNullableReturnTypeDeclarationRule.php +++ b/src/Methods/NoNullableReturnTypeDeclarationRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Reflection; @@ -55,7 +56,7 @@ public function processNode( )); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString())->build(), ]; } @@ -66,7 +67,7 @@ public function processNode( )); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString())->build(), ]; } diff --git a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php index 5ed0ae8c..6f1c9fa1 100644 --- a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Reflection; @@ -167,7 +168,7 @@ private static function createError( $classUsedInTypeDeclaration->getName(), )); - return $ruleErrorBuilder->build(); + return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString())->build(); } $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( @@ -178,6 +179,6 @@ private static function createError( $classUsedInTypeDeclaration->getName(), )); - return $ruleErrorBuilder->build(); + return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString())->build(); } } diff --git a/src/Methods/NoParameterWithNullDefaultValueRule.php b/src/Methods/NoParameterWithNullDefaultValueRule.php index cd4f54f8..148b5f28 100644 --- a/src/Methods/NoParameterWithNullDefaultValueRule.php +++ b/src/Methods/NoParameterWithNullDefaultValueRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Reflection; @@ -76,13 +77,13 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->build(); + return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString())->build(); }, $params); } $className = $classReflection->getName(); - return \array_map(static function (Node\Param $node) use ($className, $methodName): Rules\RuleError { + return \array_values(\array_map(static function (Node\Param $node) use ($className, $methodName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $node->var; @@ -96,7 +97,7 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->build(); - }, $params); + return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString())->build(); + }, $params)); } } diff --git a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php index ba5283dc..3c5467df 100644 --- a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Reflection; @@ -59,7 +60,7 @@ public function processNode( $classReflection = $scope->getClassReflection(); if ($classReflection->isAnonymous()) { - return \array_map(static function (Node\Param $node) use ($methodName): Rules\RuleError { + return \array_values(\array_map(static function (Node\Param $node) use ($methodName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $node->var; @@ -72,13 +73,13 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->build(); - }, $params); + return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString())->build(); + }, $params)); } $className = $classReflection->getName(); - return \array_map(static function (Node\Param $node) use ($className, $methodName): Rules\RuleError { + return \array_values(\array_map(static function (Node\Param $node) use ($className, $methodName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $node->var; @@ -92,8 +93,8 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->build(); - }, $params); + return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString())->build(); + }, $params)); } private static function isNullable(Node\Param $node): bool diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index aad66be0..249cc9fb 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Reflection; @@ -75,7 +76,7 @@ public function processNode( )); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::privateInFinalClass()->toString())->build(), ]; } } diff --git a/src/Statements/NoSwitchRule.php b/src/Statements/NoSwitchRule.php index 1845a224..6394e312 100644 --- a/src/Statements/NoSwitchRule.php +++ b/src/Statements/NoSwitchRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Statements; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Rules; @@ -34,7 +35,7 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Control structures using switch should not be used.'); return [ - $ruleErrorBuilder->build(), + $ruleErrorBuilder->identifier(ErrorIdentifier::noSwitch()->toString())->build(), ]; } } diff --git a/test/Integration/Classes/FinalRuleTest.php b/test/Integration/Classes/FinalRuleTest.php index 3ee9e75d..1abffd59 100644 --- a/test/Integration/Classes/FinalRuleTest.php +++ b/test/Integration/Classes/FinalRuleTest.php @@ -14,12 +14,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Classes; use Ergebnis\PHPStan\Rules\Classes; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; use PHPStan\Rules; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Classes\FinalRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class FinalRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php b/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php index 55a956e5..6362dcd9 100644 --- a/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php +++ b/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php @@ -14,12 +14,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Classes; use Ergebnis\PHPStan\Rules\Classes; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; use PHPStan\Rules; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Classes\FinalRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class FinalRuleWithAbstractClassesAllowedTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Classes/FinalRuleWithAttributesTest.php b/test/Integration/Classes/FinalRuleWithAttributesTest.php index c63564ee..19eb183a 100644 --- a/test/Integration/Classes/FinalRuleWithAttributesTest.php +++ b/test/Integration/Classes/FinalRuleWithAttributesTest.php @@ -14,12 +14,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Classes; use Ergebnis\PHPStan\Rules\Classes; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; use PHPStan\Rules; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Classes\FinalRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class FinalRuleWithAttributesTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php b/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php index c6acc2ec..ad17c1a0 100644 --- a/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php +++ b/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php @@ -14,12 +14,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Classes; use Ergebnis\PHPStan\Rules\Classes; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; use PHPStan\Rules; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Classes\FinalRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class FinalRuleWithExcludedClassNamesTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Classes/NoExtendsRuleTest.php b/test/Integration/Classes/NoExtendsRuleTest.php index 5d1aa87c..ef1f122e 100644 --- a/test/Integration/Classes/NoExtendsRuleTest.php +++ b/test/Integration/Classes/NoExtendsRuleTest.php @@ -14,12 +14,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Classes; use Ergebnis\PHPStan\Rules\Classes; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; use PHPStan\Rules; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Classes\NoExtendsRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoExtendsRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php b/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php index b1ad531c..4b9fe561 100644 --- a/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php +++ b/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php @@ -14,12 +14,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Classes; use Ergebnis\PHPStan\Rules\Classes; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; use PHPStan\Rules; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Classes\NoExtendsRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoExtendsRuleWithClassesAllowedToBeExtendedTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php b/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php index 49d50a2d..cabb373f 100644 --- a/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php +++ b/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php @@ -14,12 +14,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Classes\PHPUnit\Framework; use Ergebnis\PHPStan\Rules\Classes; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; use PHPStan\Rules; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Classes\PHPUnit\Framework\TestCaseWithSuffixRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class TestCaseWithSuffixRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php index ddd978f0..ff5d68aa 100644 --- a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php @@ -14,12 +14,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Closures; use Ergebnis\PHPStan\Rules\Closures; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; use PHPStan\Rules; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Closures\NoNullableReturnTypeDeclarationRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoNullableReturnTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php index f348f98c..1bff620c 100644 --- a/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php @@ -14,12 +14,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Closures; use Ergebnis\PHPStan\Rules\Closures; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; use PHPStan\Rules; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Closures\NoParameterWithNullDefaultValueRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoParameterWithNullDefaultValueRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php index e7504498..b15fc45c 100644 --- a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -14,12 +14,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Closures; use Ergebnis\PHPStan\Rules\Closures; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; use PHPStan\Rules; use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Closures\NoParameterWithNullableTypeDeclarationRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoParameterWithNullableTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Expressions/NoCompactRuleTest.php b/test/Integration/Expressions/NoCompactRuleTest.php index db6ed075..4d50f50f 100644 --- a/test/Integration/Expressions/NoCompactRuleTest.php +++ b/test/Integration/Expressions/NoCompactRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Expressions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Expressions; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Expressions\NoCompactRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoCompactRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Expressions/NoErrorSuppressionRuleTest.php b/test/Integration/Expressions/NoErrorSuppressionRuleTest.php index 59af8d53..d2edce35 100644 --- a/test/Integration/Expressions/NoErrorSuppressionRuleTest.php +++ b/test/Integration/Expressions/NoErrorSuppressionRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Expressions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Expressions; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Expressions\NoErrorSuppressionRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoErrorSuppressionRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Expressions/NoEvalRuleTest.php b/test/Integration/Expressions/NoEvalRuleTest.php index fb076560..8e2282d0 100644 --- a/test/Integration/Expressions/NoEvalRuleTest.php +++ b/test/Integration/Expressions/NoEvalRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Expressions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Expressions; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Expressions\NoEvalRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoEvalRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Expressions/NoIssetRuleTest.php b/test/Integration/Expressions/NoIssetRuleTest.php index b87ff715..4f398b8a 100644 --- a/test/Integration/Expressions/NoIssetRuleTest.php +++ b/test/Integration/Expressions/NoIssetRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Expressions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Expressions; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Expressions\NoIssetRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoIssetRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Files/DeclareStrictTypesRuleTest.php b/test/Integration/Files/DeclareStrictTypesRuleTest.php index 7283a01e..293398f9 100644 --- a/test/Integration/Files/DeclareStrictTypesRuleTest.php +++ b/test/Integration/Files/DeclareStrictTypesRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Files; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Files; use Ergebnis\PHPStan\Rules\Test; use PHPStan\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Files\DeclareStrictTypesRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class DeclareStrictTypesRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php index d8a1cfb0..7ed86906 100644 --- a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Functions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Functions; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Functions\NoNullableReturnTypeDeclarationRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoNullableReturnTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php index cfc0297c..890a9c23 100644 --- a/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Functions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Functions; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Functions\NoParameterWithNullDefaultValueRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoParameterWithNullDefaultValueRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php index 0456bd0a..f08f2e03 100644 --- a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Functions; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Functions; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Functions\NoParameterWithNullableTypeDeclarationRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoParameterWithNullableTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Methods/FinalInAbstractClassRuleTest.php b/test/Integration/Methods/FinalInAbstractClassRuleTest.php index d5391f5a..2d0c8f82 100644 --- a/test/Integration/Methods/FinalInAbstractClassRuleTest.php +++ b/test/Integration/Methods/FinalInAbstractClassRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Methods\FinalInAbstractClassRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class FinalInAbstractClassRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php b/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php index 66f0008c..5c25b206 100644 --- a/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php +++ b/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Methods\NoConstructorParameterWithDefaultValueRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoConstructorParameterWithDefaultValueRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php index 05e7df68..f3197337 100644 --- a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Methods\NoNullableReturnTypeDeclarationRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoNullableReturnTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php b/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php index c9d587e7..9293c73d 100644 --- a/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -21,6 +22,7 @@ use Psr\Container; #[Framework\Attributes\CoversClass(Methods\NoParameterWithContainerTypeDeclarationRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoParameterWithContainerTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php index 88a29589..767c4191 100644 --- a/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Methods\NoParameterWithNullDefaultValueRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoParameterWithNullDefaultValueRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php index c3c0e328..bb37ad38 100644 --- a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Methods\NoParameterWithNullableTypeDeclarationRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoParameterWithNullableTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Methods/PrivateInFinalClassRuleTest.php b/test/Integration/Methods/PrivateInFinalClassRuleTest.php index 691bbfc8..0095939f 100644 --- a/test/Integration/Methods/PrivateInFinalClassRuleTest.php +++ b/test/Integration/Methods/PrivateInFinalClassRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Methods; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Methods\PrivateInFinalClassRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class PrivateInFinalClassRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Integration/Statements/NoSwitchRuleTest.php b/test/Integration/Statements/NoSwitchRuleTest.php index 89093a73..b9d95950 100644 --- a/test/Integration/Statements/NoSwitchRuleTest.php +++ b/test/Integration/Statements/NoSwitchRuleTest.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Statements; +use Ergebnis\PHPStan\Rules\ErrorIdentifier; use Ergebnis\PHPStan\Rules\Statements; use Ergebnis\PHPStan\Rules\Test; use PhpParser\Node; @@ -20,6 +21,7 @@ use PHPUnit\Framework; #[Framework\Attributes\CoversClass(Statements\NoSwitchRule::class)] +#[Framework\Attributes\UsesClass(ErrorIdentifier::class)] final class NoSwitchRuleTest extends Test\Integration\AbstractTestCase { public static function provideCasesWhereAnalysisShouldSucceed(): iterable diff --git a/test/Unit/ErrorIdentifierTest.php b/test/Unit/ErrorIdentifierTest.php new file mode 100644 index 00000000..bd138b53 --- /dev/null +++ b/test/Unit/ErrorIdentifierTest.php @@ -0,0 +1,133 @@ +toString()); + } + + public function testFinalInAbstractClassReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::finalInAbstractClass(); + + self::assertSame('ergebnis.finalInAbstractClass', $errorIdentifier->toString()); + } + + public function testFinalReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::final(); + + self::assertSame('ergebnis.final', $errorIdentifier->toString()); + } + + public function testNoCompactReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::noCompact(); + + self::assertSame('ergebnis.noCompact', $errorIdentifier->toString()); + } + + public function testNoConstructorParameterWithDefaultValueReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::noConstructorParameterWithDefaultValue(); + + self::assertSame('ergebnis.noConstructorParameterWithDefaultValue', $errorIdentifier->toString()); + } + + public function testNoErrorSuppressionReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::noErrorSuppression(); + + self::assertSame('ergebnis.noErrorSuppression', $errorIdentifier->toString()); + } + + public function testNoExtendsReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::noExtends(); + + self::assertSame('ergebnis.noExtends', $errorIdentifier->toString()); + } + + public function testNoEvalReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::noEval(); + + self::assertSame('ergebnis.noEval', $errorIdentifier->toString()); + } + + public function testNoIssetReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::noIsset(); + + self::assertSame('ergebnis.noIsset', $errorIdentifier->toString()); + } + + public function testNoNullableReturnTypeDeclarationReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::noNullableReturnTypeDeclaration(); + + self::assertSame('ergebnis.noNullableReturnTypeDeclaration', $errorIdentifier->toString()); + } + + public function testNoParameterWithContainerTypeDeclarationReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::noParameterWithContainerTypeDeclaration(); + + self::assertSame('ergebnis.noParameterWithContainerTypeDeclaration', $errorIdentifier->toString()); + } + + public function testNoParameterWithNullDefaultValueReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::noParameterWithNullDefaultValue(); + + self::assertSame('ergebnis.noParameterWithNullDefaultValue', $errorIdentifier->toString()); + } + + public function testNoParameterWithNullableTypeDeclarationReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::noParameterWithNullableTypeDeclaration(); + + self::assertSame('ergebnis.noParameterWithNullableTypeDeclaration', $errorIdentifier->toString()); + } + + public function testNoSwitchReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::noSwitch(); + + self::assertSame('ergebnis.noSwitch', $errorIdentifier->toString()); + } + + public function testPrivateInFinalClassReturnsErrorIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::privateInFinalClass(); + + self::assertSame('ergebnis.privateInFinalClass', $errorIdentifier->toString()); + } + + public function testTestCaseWithSuffixIdentifier(): void + { + $errorIdentifier = ErrorIdentifier::testCaseWithSuffix(); + + self::assertSame('ergebnis.testCaseWithSuffix', $errorIdentifier->toString()); + } +} diff --git a/test/Integration/phpunit.xml b/test/phpunit.xml similarity index 62% rename from test/Integration/phpunit.xml rename to test/phpunit.xml index 7e763984..d2508df2 100644 --- a/test/Integration/phpunit.xml +++ b/test/phpunit.xml @@ -1,13 +1,13 @@ - ../../src/ + ../src/ - - . + + Integration/ + + + Unit/