From 27692474647f4139479bdc58f57d6ab17d01ca8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 1 Dec 2024 17:52:23 +0100 Subject: [PATCH 01/93] Fix: Return type declaration --- src/Methods/NoParameterWithContainerTypeDeclarationRule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php index 0e282050..397914d6 100644 --- a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php @@ -150,7 +150,7 @@ private static function createError( string $methodName, string $parameterName, Reflection\ClassReflection $classUsedInTypeDeclaration - ): Rules\RuleError { + ): Rules\IdentifierRuleError { if ($classReflection->isAnonymous()) { $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( 'Method %s() in anonymous class has a parameter $%s with a type declaration of %s, but containers should not be injected.', From f72567fdae2f80d629e5a35abea9b73b4b5ee329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 1 Dec 2024 18:02:49 +0100 Subject: [PATCH 02/93] Fix: Use more generic return type declaration --- src/Methods/NoParameterWithContainerTypeDeclarationRule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php index 397914d6..0e282050 100644 --- a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php @@ -150,7 +150,7 @@ private static function createError( string $methodName, string $parameterName, Reflection\ClassReflection $classUsedInTypeDeclaration - ): Rules\IdentifierRuleError { + ): Rules\RuleError { if ($classReflection->isAnonymous()) { $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( 'Method %s() in anonymous class has a parameter $%s with a type declaration of %s, but containers should not be injected.', From 684e01c313c5a4f2ff3c0e0156c1a76dff7a38c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 1 Dec 2024 17:58:49 +0100 Subject: [PATCH 03/93] Fix: Return RuleError with identifier --- CHANGELOG.md | 5 +++++ .../NoConstructorParameterWithDefaultValueRule.php | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f475c7ae..91cf3f95 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.5.0...main`][2.5.0...main]. +### Fixed + +- Returned rule with error identifier ([#882]), by [@localheinz] + ## [`2.5.0`][2.5.0] For a full diff see [`2.4.0...2.5.0`][2.4.0...2.5.0]. @@ -543,6 +547,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [#877]: https://github.com/ergebnis/phpstan-rules/pull/877 [#878]: https://github.com/ergebnis/phpstan-rules/pull/878 [#880]: https://github.com/ergebnis/phpstan-rules/pull/880 +[#882]: https://github.com/ergebnis/phpstan-rules/pull/882 [@enumag]: https://github.com/enumag [@ergebnis]: https://github.com/ergebnis diff --git a/src/Methods/NoConstructorParameterWithDefaultValueRule.php b/src/Methods/NoConstructorParameterWithDefaultValueRule.php index 9e43803d..7177508c 100644 --- a/src/Methods/NoConstructorParameterWithDefaultValueRule.php +++ b/src/Methods/NoConstructorParameterWithDefaultValueRule.php @@ -71,18 +71,20 @@ public function processNode( $className = $classReflection->getName(); - return \array_values(\array_map(static function (Node\Param $node) use ($className): string { + return \array_values(\array_map(static function (Node\Param $node) use ($className): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $node->var; /** @var string $parameterName */ $parameterName = $variable->name; - return \sprintf( + $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( 'Constructor in %s has parameter $%s with default value.', $className, $parameterName, - ); + )); + + return $ruleErrorBuilder->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString())->build(); }, $params)); } } From 1a4a3ddb37fb3d5869c7ebfae995efa89f68db02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 8 Nov 2021 16:28:00 +0100 Subject: [PATCH 04/93] Fix: Adjust Methods\FinalInAbstractClassRule to ignore Doctrine entities --- CHANGELOG.md | 2 + README.md | 5 ++ composer-require-checker.json | 2 + src/Methods/FinalInAbstractClassRule.php | 48 +++++++++++++++++++ ...ndEmbeddableAnnotationInInlineDocBlock.php | 13 +++++ ...mbeddableAnnotationInMultilineDocBlock.php | 15 ++++++ ...hProtectedMethodAndEmbeddableAttribute.php | 15 ++++++ ...hodAndEntityAnnotationInInlineDocBlock.php | 13 +++++ ...AndEntityAnnotationInMultilineDocBlock.php | 15 ++++++ ...sWithProtectedMethodAndEntityAttribute.php | 15 ++++++ ...rmEmbeddableAnnotationInInlineDocBlock.php | 13 +++++ ...mbeddableAnnotationInMultilineDocBlock.php | 15 ++++++ ...AndOrmEntityAnnotationInInlineDocBlock.php | 13 +++++ ...OrmEntityAnnotationInMultilineDocBlock.php | 15 ++++++ ...ngEmbeddableAnnotationInInlineDocBlock.php | 13 +++++ ...mbeddableAnnotationInMultilineDocBlock.php | 15 ++++++ ...appingEntityAnnotationInInlineDocBlock.php | 13 +++++ ...ingEntityAnnotationInMultilineDocBlock.php | 15 ++++++ ...ndEmbeddableAnnotationInInlineDocBlock.php | 13 +++++ ...mbeddableAnnotationInMultilineDocBlock.php | 15 ++++++ ...WithPublicMethodAndEmbeddableAttribute.php | 15 ++++++ ...hodAndEntityAnnotationInInlineDocBlock.php | 13 +++++ ...AndEntityAnnotationInMultilineDocBlock.php | 15 ++++++ ...lassWithPublicMethodAndEntityAttribute.php | 15 ++++++ ...rmEmbeddableAnnotationInInlineDocBlock.php | 13 +++++ ...mbeddableAnnotationInMultilineDocBlock.php | 15 ++++++ ...AndOrmEntityAnnotationInInlineDocBlock.php | 13 +++++ ...OrmEntityAnnotationInMultilineDocBlock.php | 15 ++++++ ...ngEmbeddableAnnotationInInlineDocBlock.php | 13 +++++ ...mbeddableAnnotationInMultilineDocBlock.php | 15 ++++++ ...appingEntityAnnotationInInlineDocBlock.php | 13 +++++ ...ingEntityAnnotationInMultilineDocBlock.php | 15 ++++++ .../Methods/FinalInAbstractClassRuleTest.php | 28 +++++++++++ 33 files changed, 481 insertions(+) create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInInlineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInMultilineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAttribute.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEntityAnnotationInInlineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEntityAnnotationInMultilineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEntityAttribute.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEmbeddableAnnotationInInlineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEmbeddableAnnotationInMultilineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEntityAnnotationInInlineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEntityAnnotationInMultilineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEmbeddableAnnotationInInlineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEmbeddableAnnotationInMultilineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEntityAnnotationInInlineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEntityAnnotationInMultilineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEmbeddableAnnotationInInlineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEmbeddableAnnotationInMultilineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEmbeddableAttribute.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEntityAnnotationInInlineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEntityAnnotationInMultilineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEntityAttribute.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEmbeddableAnnotationInInlineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEmbeddableAnnotationInMultilineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEntityAnnotationInInlineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEntityAnnotationInMultilineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEmbeddableAnnotationInInlineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEmbeddableAnnotationInMultilineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEntityAnnotationInInlineDocBlock.php create mode 100644 test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEntityAnnotationInMultilineDocBlock.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 91cf3f95..8e500f1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ For a full diff see [`2.5.0...main`][2.5.0...main]. ### Fixed - Returned rule with error identifier ([#882]), by [@localheinz] +- Adjusted `Methods\FinalInAbstractClassRule` to ignore Doctrine embeddables and entities ([#396]), by [@localheinz] ## [`2.5.0`][2.5.0] @@ -531,6 +532,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [#294]: https://github.com/ergebnis/phpstan-rules/pull/294 [#381]: https://github.com/ergebnis/phpstan-rules/pull/381 [#395]: https://github.com/ergebnis/phpstan-rules/pull/395 +[#396]: https://github.com/ergebnis/phpstan-rules/pull/396 [#496]: https://github.com/ergebnis/phpstan-rules/pull/496 [#498]: https://github.com/ergebnis/phpstan-rules/pull/498 [#499]: https://github.com/ergebnis/phpstan-rules/pull/498 diff --git a/README.md b/README.md index c6bef802..03926cc1 100644 --- a/README.md +++ b/README.md @@ -345,6 +345,11 @@ parameters: This rule reports an error when a concrete `public` or `protected `method in an `abstract` class is not `final`. +:bulb: This rule ignores + +- Doctrine embeddables +- Doctrine entities + ##### Disabling the rule You can set the the `enabled` parameter to `false` to disable this rule. diff --git a/composer-require-checker.json b/composer-require-checker.json index 80e14648..0dc15360 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -26,6 +26,8 @@ "PhpParser\\Node\\UnionType", "PHPStan\\Analyser\\Scope", "PHPStan\\Node\\FileNode", + "PHPStan\\PhpDoc\\ResolvedPhpDocBlock", + "PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTagNode", "PHPStan\\Reflection\\ClassReflection", "PHPStan\\Reflection\\ReflectionProvider", "PHPStan\\Rules\\Rule", diff --git a/src/Methods/FinalInAbstractClassRule.php b/src/Methods/FinalInAbstractClassRule.php index 88c8fdfe..7c90aee1 100644 --- a/src/Methods/FinalInAbstractClassRule.php +++ b/src/Methods/FinalInAbstractClassRule.php @@ -16,6 +16,8 @@ use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; +use PHPStan\PhpDoc; +use PHPStan\PhpDocParser; use PHPStan\Reflection; use PHPStan\Rules; @@ -24,6 +26,19 @@ */ final class FinalInAbstractClassRule implements Rules\Rule { + private const DOCTRINE_ATTRIBUTE_NAMES = [ + 'Doctrine\\ORM\\Mapping\\Embeddable', + 'Doctrine\\ORM\\Mapping\\Entity', + ]; + private const DOCTRINE_TAG_NAMES = [ + '@ORM\\Mapping\\Embeddable', + '@ORM\\Embeddable', + '@Embeddable', + '@ORM\\Mapping\\Entity', + '@ORM\\Entity', + '@Entity', + ]; + public function getNodeType(): string { return Node\Stmt\ClassMethod::class; @@ -36,6 +51,10 @@ public function processNode( /** @var Reflection\ClassReflection $containingClass */ $containingClass = $scope->getClassReflection(); + if (self::isDoctrineEntity($containingClass)) { + return []; + } + if (!$containingClass->isAbstract()) { return []; } @@ -70,4 +89,33 @@ public function processNode( $ruleErrorBuilder->identifier(ErrorIdentifier::finalInAbstractClass()->toString())->build(), ]; } + + private static function isDoctrineEntity(Reflection\ClassReflection $containingClass): bool + { + $attributes = $containingClass->getNativeReflection()->getAttributes(); + + foreach ($attributes as $attribute) { + if (\in_array($attribute->getName(), self::DOCTRINE_ATTRIBUTE_NAMES, true)) { + return true; + } + } + + $resolvedPhpDocBlock = $containingClass->getResolvedPhpDoc(); + + if ($resolvedPhpDocBlock instanceof PhpDoc\ResolvedPhpDocBlock) { + foreach ($resolvedPhpDocBlock->getPhpDocNodes() as $phpDocNode) { + foreach ($phpDocNode->children as $child) { + if (!$child instanceof PhpDocParser\Ast\PhpDoc\PhpDocTagNode) { + continue; + } + + if (\in_array($child->name, self::DOCTRINE_TAG_NAMES, true)) { + return true; + } + } + } + } + + return false; + } } diff --git a/test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInInlineDocBlock.php b/test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInInlineDocBlock.php new file mode 100644 index 00000000..ceb7dae7 --- /dev/null +++ b/test/Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInInlineDocBlock.php @@ -0,0 +1,13 @@ + __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithFinalPublicMethod.php', 'abstract-class-with-non-final-constructor' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithNonFinalConstructor.php', 'abstract-class-with-private-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPrivateMethod.php', + 'abstract-class-with-protected-method-and-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInInlineDocBlock.php', + 'abstract-class-with-protected-method-and-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInMultilineDocBlock.php', + 'abstract-class-with-protected-method-and-embeddable-attribute' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAttribute.php', + 'abstract-class-with-protected-method-and-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEntityAnnotationInInlineDocBlock.php', + 'abstract-class-with-protected-method-and-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEntityAnnotationInMultilineDocBlock.php', + 'abstract-class-with-protected-method-and-entity-attribute' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEntityAttribute.php', + 'abstract-class-with-protected-method-and-orm-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEmbeddableAnnotationInMultilineDocBlock.php', + 'abstract-class-with-protected-method-and-orm-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEmbeddableAnnotationInInlineDocBlock.php', + 'abstract-class-with-protected-method-and-orm-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEntityAnnotationInMultilineDocBlock.php', + 'abstract-class-with-protected-method-and-orm-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEntityAnnotationInInlineDocBlock.php', + 'abstract-class-with-protected-method-and-orm-mapping-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEmbeddableAnnotationInInlineDocBlock.php', + 'abstract-class-with-protected-method-and-orm-mapping-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEmbeddableAnnotationInMultilineDocBlock.php', + 'abstract-class-with-protected-method-and-orm-mapping-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEntityAnnotationInInlineDocBlock.php', + 'abstract-class-with-protected-method-and-orm-mapping-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEntityAnnotationInMultilineDocBlock.php', + 'abstract-class-with-public-method-and-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEmbeddableAnnotationInInlineDocBlock.php', + 'abstract-class-with-public-method-and-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEmbeddableAnnotationInMultilineDocBlock.php', + 'abstract-class-with-public-method-and-embeddable-attribute' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEmbeddableAttribute.php', + 'abstract-class-with-public-method-and-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEntityAnnotationInInlineDocBlock.php', + 'abstract-class-with-public-method-and-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEntityAnnotationInMultilineDocBlock.php', + 'abstract-class-with-public-method-and-entity-attribute' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEntityAttribute.php', + 'abstract-class-with-public-method-and-orm-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEmbeddableAnnotationInMultilineDocBlock.php', + 'abstract-class-with-public-method-and-orm-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEmbeddableAnnotationInInlineDocBlock.php', + 'abstract-class-with-public-method-and-orm-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEntityAnnotationInMultilineDocBlock.php', + 'abstract-class-with-public-method-and-orm-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEntityAnnotationInInlineDocBlock.php', + 'abstract-class-with-public-method-and-orm-mapping-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEmbeddableAnnotationInInlineDocBlock.php', + 'abstract-class-with-public-method-and-orm-mapping-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEmbeddableAnnotationInMultilineDocBlock.php', + 'abstract-class-with-public-method-and-orm-mapping-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEntityAnnotationInInlineDocBlock.php', + 'abstract-class-with-public-method-and-orm-mapping-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEntityAnnotationInMultilineDocBlock.php', 'interface-with-public-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/InterfaceWithPublicMethod.php', ]; From a42a933e38d301f332b404dde4eff8ab5638191b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 Dec 2024 18:46:13 +0000 Subject: [PATCH 05/93] composer(deps-dev): Bump ergebnis/composer-normalize Bumps [ergebnis/composer-normalize](https://github.com/ergebnis/composer-normalize) from 2.44.0 to 2.45.0. - [Release notes](https://github.com/ergebnis/composer-normalize/releases) - [Changelog](https://github.com/ergebnis/composer-normalize/blob/main/CHANGELOG.md) - [Commits](https://github.com/ergebnis/composer-normalize/compare/2.44.0...2.45.0) --- updated-dependencies: - dependency-name: ergebnis/composer-normalize dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.json | 2 +- composer.lock | 298 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 248 insertions(+), 52 deletions(-) diff --git a/composer.json b/composer.json index ae7afdce..25f091eb 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ }, "require-dev": { "doctrine/orm": "^2.20.0 || ^3.3.0", - "ergebnis/composer-normalize": "^2.44.0", + "ergebnis/composer-normalize": "^2.45.0", "ergebnis/license": "^2.6.0", "ergebnis/php-cs-fixer-config": "^6.39.0", "ergebnis/phpunit-slow-test-detector": "^2.17.0", diff --git a/composer.lock b/composer.lock index b5d983a7..2088f2f7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3a5b5d491d8b92aeebdaefc6d6f38f07", + "content-hash": "0632a3de04ffa3a44297212ff2984c46", "packages": [ { "name": "phpstan/phpstan", @@ -1302,49 +1302,55 @@ }, { "name": "ergebnis/composer-normalize", - "version": "2.44.0", + "version": "2.45.0", "source": { "type": "git", "url": "https://github.com/ergebnis/composer-normalize.git", - "reference": "bd0c446426bb837ae0cc9f97948167e658bd11d2" + "reference": "bb82b484bed2556da6311b9eff779fa7e73ce937" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ergebnis/composer-normalize/zipball/bd0c446426bb837ae0cc9f97948167e658bd11d2", - "reference": "bd0c446426bb837ae0cc9f97948167e658bd11d2", + "url": "https://api.github.com/repos/ergebnis/composer-normalize/zipball/bb82b484bed2556da6311b9eff779fa7e73ce937", + "reference": "bb82b484bed2556da6311b9eff779fa7e73ce937", "shasum": "" }, "require": { "composer-plugin-api": "^2.0.0", - "ergebnis/json": "^1.2.0", - "ergebnis/json-normalizer": "^4.5.0", - "ergebnis/json-printer": "^3.5.0", + "ergebnis/json": "^1.4.0", + "ergebnis/json-normalizer": "^4.8.0", + "ergebnis/json-printer": "^3.7.0", "ext-json": "*", - "justinrainbow/json-schema": "^5.2.12", - "localheinz/diff": "^1.1.1", + "justinrainbow/json-schema": "^5.2.12 || ^6.0.0", + "localheinz/diff": "^1.2.0", "php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0" }, "require-dev": { - "composer/composer": "^2.7.7", - "ergebnis/license": "^2.5.0", - "ergebnis/php-cs-fixer-config": "^6.37.0", - "ergebnis/phpunit-slow-test-detector": "^2.16.0", - "fakerphp/faker": "^1.23.1", + "composer/composer": "^2.8.3", + "ergebnis/license": "^2.6.0", + "ergebnis/php-cs-fixer-config": "^6.39.0", + "ergebnis/phpunit-slow-test-detector": "^2.17.0", + "fakerphp/faker": "^1.24.1", "infection/infection": "~0.26.6", + "phpstan/extension-installer": "^1.4.3", + "phpstan/phpstan": "^1.12.12", + "phpstan/phpstan-deprecation-rules": "^1.2.1", + "phpstan/phpstan-phpunit": "^1.4.1", + "phpstan/phpstan-strict-rules": "^1.6.1", "phpunit/phpunit": "^9.6.20", - "psalm/plugin-phpunit": "~0.19.0", - "rector/rector": "^1.2.5", - "symfony/filesystem": "^5.4.41", - "vimeo/psalm": "^5.26.1" + "rector/rector": "^1.2.10", + "symfony/filesystem": "^5.4.41" }, "type": "composer-plugin", "extra": { "class": "Ergebnis\\Composer\\Normalize\\NormalizePlugin", + "branch-alias": { + "dev-main": "2.44-dev" + }, + "plugin-optional": true, "composer-normalize": { "indent-size": 2, "indent-style": "space" - }, - "plugin-optional": true + } }, "autoload": { "psr-4": { @@ -1375,7 +1381,7 @@ "security": "https://github.com/ergebnis/composer-normalize/blob/main/.github/SECURITY.md", "source": "https://github.com/ergebnis/composer-normalize" }, - "time": "2024-09-30T21:56:22+00:00" + "time": "2024-12-04T18:36:37+00:00" }, { "name": "ergebnis/json", @@ -1447,16 +1453,16 @@ }, { "name": "ergebnis/json-normalizer", - "version": "4.7.0", + "version": "4.8.0", "source": { "type": "git", "url": "https://github.com/ergebnis/json-normalizer.git", - "reference": "36d86389095736944a5954ec440552bbe92e425f" + "reference": "e3a477b62808f377f4fc69a50f9eb66ec102747b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ergebnis/json-normalizer/zipball/36d86389095736944a5954ec440552bbe92e425f", - "reference": "36d86389095736944a5954ec440552bbe92e425f", + "url": "https://api.github.com/repos/ergebnis/json-normalizer/zipball/e3a477b62808f377f4fc69a50f9eb66ec102747b", + "reference": "e3a477b62808f377f4fc69a50f9eb66ec102747b", "shasum": "" }, "require": { @@ -1465,7 +1471,7 @@ "ergebnis/json-printer": "^3.5.0", "ergebnis/json-schema-validator": "^4.2.0", "ext-json": "*", - "justinrainbow/json-schema": "^5.2.12", + "justinrainbow/json-schema": "^5.2.12 || ^6.0.0", "php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0" }, "require-dev": { @@ -1491,7 +1497,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "4.7-dev" + "dev-main": "4.8-dev" }, "composer-normalize": { "indent-size": 2, @@ -1525,7 +1531,7 @@ "security": "https://github.com/ergebnis/json-normalizer/blob/main/.github/SECURITY.md", "source": "https://github.com/ergebnis/json-normalizer" }, - "time": "2024-11-17T20:34:42+00:00" + "time": "2024-12-04T16:48:55+00:00" }, { "name": "ergebnis/json-pointer", @@ -2235,25 +2241,142 @@ ], "time": "2024-11-25T00:39:24+00:00" }, + { + "name": "icecave/parity", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/icecave/parity.git", + "reference": "0109fef58b3230d23b20b2ac52ecdf477218d300" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/icecave/parity/zipball/0109fef58b3230d23b20b2ac52ecdf477218d300", + "reference": "0109fef58b3230d23b20b2ac52ecdf477218d300", + "shasum": "" + }, + "require": { + "icecave/repr": "~1", + "php": ">=5.3" + }, + "require-dev": { + "eloquent/liberator": "~1", + "icecave/archer": "~1" + }, + "suggest": { + "eloquent/asplode": "Drop-in exception-based error handling." + }, + "type": "library", + "autoload": { + "psr-0": { + "Icecave\\Parity": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "James Harris", + "email": "james.harris@icecave.com.au", + "homepage": "https://github.com/jmalloc" + } + ], + "description": "A customizable deep comparison library.", + "homepage": "https://github.com/IcecaveStudios/parity", + "keywords": [ + "compare", + "comparison", + "equal", + "equality", + "greater", + "less", + "sort", + "sorting" + ], + "support": { + "issues": "https://github.com/icecave/parity/issues", + "source": "https://github.com/icecave/parity/tree/1.0.0" + }, + "time": "2014-01-17T05:56:27+00:00" + }, + { + "name": "icecave/repr", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/icecave/repr.git", + "reference": "8a3d2953adf5f464a06e3e2587aeacc97e2bed07" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/icecave/repr/zipball/8a3d2953adf5f464a06e3e2587aeacc97e2bed07", + "reference": "8a3d2953adf5f464a06e3e2587aeacc97e2bed07", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "icecave/archer": "~1" + }, + "suggest": { + "eloquent/asplode": "Drop-in exception-based error handling." + }, + "type": "library", + "autoload": { + "psr-4": { + "Icecave\\Repr\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "James Harris", + "email": "james.harris@icecave.com.au", + "homepage": "https://github.com/jmalloc" + } + ], + "description": "A library for generating string representations of any value, inspired by Python's reprlib library.", + "homepage": "https://github.com/IcecaveStudios/repr", + "keywords": [ + "human", + "readable", + "repr", + "representation", + "string" + ], + "support": { + "issues": "https://github.com/icecave/repr/issues", + "source": "https://github.com/icecave/repr/tree/1.0.1" + }, + "time": "2014-07-25T05:44:41+00:00" + }, { "name": "justinrainbow/json-schema", - "version": "5.3.0", + "version": "6.0.0", "source": { "type": "git", "url": "https://github.com/jsonrainbow/json-schema.git", - "reference": "feb2ca6dd1cebdaf1ed60a4c8de2e53ce11c4fd8" + "reference": "a38c6198d53b09c0702f440585a4f4a5d9137bd9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jsonrainbow/json-schema/zipball/feb2ca6dd1cebdaf1ed60a4c8de2e53ce11c4fd8", - "reference": "feb2ca6dd1cebdaf1ed60a4c8de2e53ce11c4fd8", + "url": "https://api.github.com/repos/jsonrainbow/json-schema/zipball/a38c6198d53b09c0702f440585a4f4a5d9137bd9", + "reference": "a38c6198d53b09c0702f440585a4f4a5d9137bd9", "shasum": "" }, "require": { - "php": ">=7.1" + "icecave/parity": "1.0.0", + "marc-mabe/php-enum": "^2.0 || ^3.0 || ^4.0", + "php": ">=5.3.3" }, "require-dev": { - "friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1", + "friendsofphp/php-cs-fixer": "~2.2.20 || ~2.19.0", "json-schema/json-schema-test-suite": "1.2.0", "phpunit/phpunit": "^4.8.35" }, @@ -2261,6 +2384,11 @@ "bin/validate-json" ], "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.x-dev" + } + }, "autoload": { "psr-4": { "JsonSchema\\": "src/JsonSchema/" @@ -2289,16 +2417,16 @@ } ], "description": "A library to validate a json schema.", - "homepage": "https://github.com/justinrainbow/json-schema", + "homepage": "https://github.com/jsonrainbow/json-schema", "keywords": [ "json", "schema" ], "support": { "issues": "https://github.com/jsonrainbow/json-schema/issues", - "source": "https://github.com/jsonrainbow/json-schema/tree/5.3.0" + "source": "https://github.com/jsonrainbow/json-schema/tree/6.0.0" }, - "time": "2024-07-06T21:00:26+00:00" + "time": "2024-07-30T17:49:21+00:00" }, { "name": "kubawerlos/php-cs-fixer-custom-fixers", @@ -2348,23 +2476,23 @@ }, { "name": "localheinz/diff", - "version": "1.1.1", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/localheinz/diff.git", - "reference": "851bb20ea8358c86f677f5f111c4ab031b1c764c" + "reference": "ec413943c2b518464865673fd5b38f7df867a010" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/localheinz/diff/zipball/851bb20ea8358c86f677f5f111c4ab031b1c764c", - "reference": "851bb20ea8358c86f677f5f111c4ab031b1c764c", + "url": "https://api.github.com/repos/localheinz/diff/zipball/ec413943c2b518464865673fd5b38f7df867a010", + "reference": "ec413943c2b518464865673fd5b38f7df867a010", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" + "php": "~7.1.0 || ~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0" }, "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.0", + "phpunit/phpunit": "^7.5.0 || ^8.5.23", "symfony/process": "^4.2 || ^5" }, "type": "library", @@ -2396,15 +2524,83 @@ "unified diff" ], "support": { - "source": "https://github.com/localheinz/diff/tree/main" + "issues": "https://github.com/localheinz/diff/issues", + "source": "https://github.com/localheinz/diff/tree/1.2.0" }, - "funding": [ + "time": "2024-12-04T14:16:01+00:00" + }, + { + "name": "marc-mabe/php-enum", + "version": "v4.7.1", + "source": { + "type": "git", + "url": "https://github.com/marc-mabe/php-enum.git", + "reference": "7159809e5cfa041dca28e61f7f7ae58063aae8ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/marc-mabe/php-enum/zipball/7159809e5cfa041dca28e61f7f7ae58063aae8ed", + "reference": "7159809e5cfa041dca28e61f7f7ae58063aae8ed", + "shasum": "" + }, + "require": { + "ext-reflection": "*", + "php": "^7.1 | ^8.0" + }, + "require-dev": { + "phpbench/phpbench": "^0.16.10 || ^1.0.4", + "phpstan/phpstan": "^1.3.1", + "phpunit/phpunit": "^7.5.20 | ^8.5.22 | ^9.5.11", + "vimeo/psalm": "^4.17.0 | ^5.26.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-3.x": "3.2-dev", + "dev-master": "4.7-dev" + } + }, + "autoload": { + "psr-4": { + "MabeEnum\\": "src/" + }, + "classmap": [ + "stubs/Stringable.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ { - "url": "https://github.com/sebastianbergmann", - "type": "github" + "name": "Marc Bennewitz", + "email": "dev@mabe.berlin", + "homepage": "https://mabe.berlin/", + "role": "Lead" } ], - "time": "2020-07-06T04:49:32+00:00" + "description": "Simple and fast implementation of enumerations with native PHP", + "homepage": "https://github.com/marc-mabe/php-enum", + "keywords": [ + "enum", + "enum-map", + "enum-set", + "enumeration", + "enumerator", + "enummap", + "enumset", + "map", + "set", + "type", + "type-hint", + "typehint" + ], + "support": { + "issues": "https://github.com/marc-mabe/php-enum/issues", + "source": "https://github.com/marc-mabe/php-enum/tree/v4.7.1" + }, + "time": "2024-11-28T04:54:44+00:00" }, { "name": "myclabs/deep-copy", @@ -6811,14 +7007,14 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { "php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", "ext-mbstring": "*" }, - "platform-dev": {}, + "platform-dev": [], "platform-overrides": { "php": "7.4.33" }, From 0f57766f1730dff1c2756aa878060fb65e064c42 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:01:27 +0000 Subject: [PATCH 06/93] github-actions(deps): Bump codecov/codecov-action from 5.0.7 to 5.1.1 Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.0.7 to 5.1.1. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v5.0.7...v5.1.1) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/integrate.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index c7f36ff4..e0ec179f 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -65,7 +65,7 @@ jobs: 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" + uses: "codecov/codecov-action@v5.1.1" with: files: ".build/phpunit/logs/clover.xml" token: "${{ secrets.CODECOV_TOKEN }}" From b7744a8afb2de97d14aba0485cbfd57fb8ab8b3c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:01:30 +0000 Subject: [PATCH 07/93] github-actions(deps): Bump actions/cache from 4.1.2 to 4.2.0 Bumps [actions/cache](https://github.com/actions/cache) from 4.1.2 to 4.2.0. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v4.1.2...v4.2.0) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/integrate.yaml | 14 +++++++------- .github/workflows/renew.yaml | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index c7f36ff4..f6f730c2 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -48,7 +48,7 @@ jobs: uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.9.2" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v4.1.2" + uses: "actions/cache@v4.2.0" with: path: "${{ env.COMPOSER_CACHE_DIR }}" key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}" @@ -113,7 +113,7 @@ jobs: uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.9.2" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v4.1.2" + uses: "actions/cache@v4.2.0" with: path: "${{ env.COMPOSER_CACHE_DIR }}" key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}" @@ -128,7 +128,7 @@ jobs: run: "composer normalize --ansi --dry-run" - name: "Cache cache directory for friendsofphp/php-cs-fixer" - uses: "actions/cache@v4.1.2" + uses: "actions/cache@v4.2.0" with: path: ".build/php-cs-fixer" key: "php-${{ matrix.php-version }}-php-cs-fixer-${{ github.ref_name }}" @@ -179,7 +179,7 @@ jobs: uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.9.2" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v4.1.2" + uses: "actions/cache@v4.2.0" with: path: "${{ env.COMPOSER_CACHE_DIR }}" key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}" @@ -234,7 +234,7 @@ jobs: uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.9.2" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v4.1.2" + uses: "actions/cache@v4.2.0" with: path: "${{ env.COMPOSER_CACHE_DIR }}" key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}" @@ -284,7 +284,7 @@ jobs: uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.9.2" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v4.1.2" + uses: "actions/cache@v4.2.0" with: path: "${{ env.COMPOSER_CACHE_DIR }}" key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}" @@ -345,7 +345,7 @@ jobs: uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.9.2" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v4.1.2" + uses: "actions/cache@v4.2.0" with: path: "${{ env.COMPOSER_CACHE_DIR }}" key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}" diff --git a/.github/workflows/renew.yaml b/.github/workflows/renew.yaml index 247a4557..a6f08104 100644 --- a/.github/workflows/renew.yaml +++ b/.github/workflows/renew.yaml @@ -45,7 +45,7 @@ jobs: uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.9.2" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v4.1.2" + uses: "actions/cache@v4.2.0" with: path: "${{ env.COMPOSER_CACHE_DIR }}" key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}" @@ -57,7 +57,7 @@ jobs: dependencies: "${{ matrix.dependencies }}" - name: "Cache cache directory for friendsofphp/php-cs-fixer" - uses: "actions/cache@v4.1.2" + uses: "actions/cache@v4.2.0" with: path: ".build/php-cs-fixer" key: "php-${{ matrix.php-version }}-php-cs-fixer-${{ github.ref_name }}" From 75b368d2c068a4244a53186b967a8b63dc350f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 07:36:10 +0100 Subject: [PATCH 08/93] Fix: Use list in DocBlocks --- src/Classes/FinalRule.php | 8 ++++---- src/Classes/NoExtendsRule.php | 6 +++--- src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php | 2 +- .../NoParameterWithContainerTypeDeclarationRule.php | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Classes/FinalRule.php b/src/Classes/FinalRule.php index 0e1af1dd..3569ff84 100644 --- a/src/Classes/FinalRule.php +++ b/src/Classes/FinalRule.php @@ -25,7 +25,7 @@ final class FinalRule implements Rules\Rule { /** - * @var array + * @var list */ private static array $whitelistedAnnotations = [ 'Entity', @@ -34,7 +34,7 @@ final class FinalRule implements Rules\Rule ]; /** - * @var array + * @var list */ private static array $whitelistedAttributes = [ 'Doctrine\ORM\Mapping\Entity', @@ -42,13 +42,13 @@ final class FinalRule implements Rules\Rule private bool $allowAbstractClasses; /** - * @var array + * @var list */ private array $classesNotRequiredToBeAbstractOrFinal; private string $errorMessageTemplate = 'Class %s is not final.'; /** - * @param array $classesNotRequiredToBeAbstractOrFinal + * @param list $classesNotRequiredToBeAbstractOrFinal */ public function __construct( bool $allowAbstractClasses, diff --git a/src/Classes/NoExtendsRule.php b/src/Classes/NoExtendsRule.php index 40e4d70f..fdc2b49f 100644 --- a/src/Classes/NoExtendsRule.php +++ b/src/Classes/NoExtendsRule.php @@ -24,19 +24,19 @@ final class NoExtendsRule implements Rules\Rule { /** - * @var array + * @var list */ private static array $defaultClassesAllowedToBeExtended = [ 'PHPUnit\\Framework\\TestCase', ]; /** - * @var array + * @var list */ private array $classesAllowedToBeExtended; /** - * @param array $classesAllowedToBeExtended + * @param list $classesAllowedToBeExtended */ public function __construct(array $classesAllowedToBeExtended) { diff --git a/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php b/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php index 7f4589a6..c3eb1e86 100644 --- a/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php +++ b/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php @@ -25,7 +25,7 @@ final class TestCaseWithSuffixRule implements Rules\Rule { /** - * @var array + * @var list */ private static array $phpunitTestCaseClassNames = [ 'PHPUnit\Framework\TestCase', diff --git a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php index 0e282050..74036492 100644 --- a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php @@ -27,18 +27,18 @@ final class NoParameterWithContainerTypeDeclarationRule implements Rules\Rule private Reflection\ReflectionProvider $reflectionProvider; /** - * @var array + * @var list */ private array $interfacesImplementedByContainers; /** - * @var array + * @var list */ private array $methodsAllowedToUseContainerTypeDeclarations; /** - * @param array $interfacesImplementedByContainers - * @param array $methodsAllowedToUseContainerTypeDeclarations + * @param list $interfacesImplementedByContainers + * @param list $methodsAllowedToUseContainerTypeDeclarations */ public function __construct( Reflection\ReflectionProvider $reflectionProvider, From e0af30f71b66ab039bd86d1f91e8cabac7e011a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 07:39:16 +0100 Subject: [PATCH 09/93] Fix: Reset keys --- src/Classes/NoExtendsRule.php | 4 ++-- .../NoParameterWithContainerTypeDeclarationRule.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Classes/NoExtendsRule.php b/src/Classes/NoExtendsRule.php index fdc2b49f..361d7997 100644 --- a/src/Classes/NoExtendsRule.php +++ b/src/Classes/NoExtendsRule.php @@ -40,13 +40,13 @@ final class NoExtendsRule implements Rules\Rule */ public function __construct(array $classesAllowedToBeExtended) { - $this->classesAllowedToBeExtended = \array_unique(\array_merge( + $this->classesAllowedToBeExtended = \array_values(\array_unique(\array_merge( self::$defaultClassesAllowedToBeExtended, \array_map(static function (string $classAllowedToBeExtended): string { /** @var class-string $classAllowedToBeExtended */ return $classAllowedToBeExtended; }, $classesAllowedToBeExtended), - )); + ))); } public function getNodeType(): string diff --git a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php index 74036492..5ea40a67 100644 --- a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php @@ -46,14 +46,14 @@ public function __construct( array $methodsAllowedToUseContainerTypeDeclarations ) { $this->reflectionProvider = $reflectionProvider; - $this->interfacesImplementedByContainers = \array_filter( + $this->interfacesImplementedByContainers = \array_values(\array_filter( \array_map(static function (string $interfaceImplementedByContainers): string { return $interfaceImplementedByContainers; }, $interfacesImplementedByContainers), static function (string $interfaceImplementedByContainer): bool { return \interface_exists($interfaceImplementedByContainer); }, - ); + )); $this->methodsAllowedToUseContainerTypeDeclarations = $methodsAllowedToUseContainerTypeDeclarations; } @@ -83,7 +83,7 @@ public function processNode( /** @var Reflection\ClassReflection $containingClass */ $containingClass = $scope->getClassReflection(); - return \array_reduce( + return \array_values(\array_reduce( $node->params, function (array $errors, Node\Param $node) use ($scope, $containingClass, $methodName) { $type = $node->type; @@ -142,7 +142,7 @@ function (array $errors, Node\Param $node) use ($scope, $containingClass, $metho return $errors; }, [], - ); + )); } private static function createError( From cb17c53b3507bec638dadc6f2c39106c93649c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 07:45:39 +0100 Subject: [PATCH 10/93] Fix: Add return type declaration --- src/Methods/NoParameterWithContainerTypeDeclarationRule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php index 5ea40a67..639441a9 100644 --- a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php @@ -85,7 +85,7 @@ public function processNode( return \array_values(\array_reduce( $node->params, - function (array $errors, Node\Param $node) use ($scope, $containingClass, $methodName) { + function (array $errors, Node\Param $node) use ($scope, $containingClass, $methodName): array { $type = $node->type; if (!$type instanceof Node\Name) { From fd1aaad0f3714825ae83c3efe40450ee87e5ad68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 07:51:00 +0100 Subject: [PATCH 11/93] Fix: Wrapping --- src/Classes/FinalRule.php | 4 +++- src/Classes/NoExtendsRule.php | 8 ++++++-- src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php | 4 +++- src/Closures/NoNullableReturnTypeDeclarationRule.php | 4 +++- src/Closures/NoParameterWithNullDefaultValueRule.php | 4 +++- .../NoParameterWithNullableTypeDeclarationRule.php | 4 +++- src/Expressions/NoCompactRule.php | 4 +++- src/Expressions/NoErrorSuppressionRule.php | 4 +++- src/Expressions/NoEvalRule.php | 4 +++- src/Expressions/NoIssetRule.php | 4 +++- src/Files/DeclareStrictTypesRule.php | 4 +++- src/Functions/NoNullableReturnTypeDeclarationRule.php | 4 +++- src/Functions/NoParameterWithNullDefaultValueRule.php | 4 +++- .../NoParameterWithNullableTypeDeclarationRule.php | 4 +++- src/Methods/FinalInAbstractClassRule.php | 4 +++- .../NoConstructorParameterWithDefaultValueRule.php | 8 ++++++-- src/Methods/NoNullableReturnTypeDeclarationRule.php | 8 ++++++-- .../NoParameterWithContainerTypeDeclarationRule.php | 8 ++++++-- src/Methods/NoParameterWithNullDefaultValueRule.php | 8 ++++++-- .../NoParameterWithNullableTypeDeclarationRule.php | 8 ++++++-- src/Methods/PrivateInFinalClassRule.php | 4 +++- src/Statements/NoSwitchRule.php | 4 +++- 22 files changed, 84 insertions(+), 28 deletions(-) diff --git a/src/Classes/FinalRule.php b/src/Classes/FinalRule.php index 3569ff84..26119ffa 100644 --- a/src/Classes/FinalRule.php +++ b/src/Classes/FinalRule.php @@ -99,7 +99,9 @@ public function processNode( )); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::final()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::final()->toString()) + ->build(), ]; } diff --git a/src/Classes/NoExtendsRule.php b/src/Classes/NoExtendsRule.php index 361d7997..42772e55 100644 --- a/src/Classes/NoExtendsRule.php +++ b/src/Classes/NoExtendsRule.php @@ -75,7 +75,9 @@ public function processNode( )); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::noExtends()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::noExtends()->toString()) + ->build(), ]; } @@ -86,7 +88,9 @@ public function processNode( )); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::noExtends()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::noExtends()->toString()) + ->build(), ]; } } diff --git a/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php b/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php index c3eb1e86..4e252daa 100644 --- a/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php +++ b/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php @@ -88,7 +88,9 @@ public function processNode( )); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::testCaseWithSuffix()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::testCaseWithSuffix()->toString()) + ->build(), ]; } } diff --git a/src/Closures/NoNullableReturnTypeDeclarationRule.php b/src/Closures/NoNullableReturnTypeDeclarationRule.php index 12ab6710..a4eba9de 100644 --- a/src/Closures/NoNullableReturnTypeDeclarationRule.php +++ b/src/Closures/NoNullableReturnTypeDeclarationRule.php @@ -39,7 +39,9 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Closure has a nullable return type declaration.'); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString()) + ->build(), ]; } diff --git a/src/Closures/NoParameterWithNullDefaultValueRule.php b/src/Closures/NoParameterWithNullDefaultValueRule.php index 83579c52..32cb1c62 100644 --- a/src/Closures/NoParameterWithNullDefaultValueRule.php +++ b/src/Closures/NoParameterWithNullDefaultValueRule.php @@ -60,7 +60,9 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString())->build(); + return $ruleErrorBuilder + ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) + ->build(); }, $params)); } } diff --git a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php index ef75bc3c..4a9b5827 100644 --- a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php @@ -56,7 +56,9 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString())->build(); + return $ruleErrorBuilder + ->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString()) + ->build(); }, $params)); } diff --git a/src/Expressions/NoCompactRule.php b/src/Expressions/NoCompactRule.php index 58da4044..8b126950 100644 --- a/src/Expressions/NoCompactRule.php +++ b/src/Expressions/NoCompactRule.php @@ -43,7 +43,9 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Function compact() should not be used.'); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::noCompact()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::noCompact()->toString()) + ->build(), ]; } } diff --git a/src/Expressions/NoErrorSuppressionRule.php b/src/Expressions/NoErrorSuppressionRule.php index 26f97c86..aeafcafe 100644 --- a/src/Expressions/NoErrorSuppressionRule.php +++ b/src/Expressions/NoErrorSuppressionRule.php @@ -35,7 +35,9 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Error suppression via "@" should not be used.'); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::noErrorSuppression()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::noErrorSuppression()->toString()) + ->build(), ]; } } diff --git a/src/Expressions/NoEvalRule.php b/src/Expressions/NoEvalRule.php index 341d4454..75af9872 100644 --- a/src/Expressions/NoEvalRule.php +++ b/src/Expressions/NoEvalRule.php @@ -35,7 +35,9 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Language construct eval() should not be used.'); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::noEval()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::noEval()->toString()) + ->build(), ]; } } diff --git a/src/Expressions/NoIssetRule.php b/src/Expressions/NoIssetRule.php index 08c1dcf6..12a76df4 100644 --- a/src/Expressions/NoIssetRule.php +++ b/src/Expressions/NoIssetRule.php @@ -35,7 +35,9 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Language construct isset() should not be used.'); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::noIsset()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::noIsset()->toString()) + ->build(), ]; } } diff --git a/src/Files/DeclareStrictTypesRule.php b/src/Files/DeclareStrictTypesRule.php index 11c615b1..66a74fd3 100644 --- a/src/Files/DeclareStrictTypesRule.php +++ b/src/Files/DeclareStrictTypesRule.php @@ -64,7 +64,9 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('File is missing a "declare(strict_types=1)" declaration.'); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::declareStrictTypes()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::declareStrictTypes()->toString()) + ->build(), ]; } } diff --git a/src/Functions/NoNullableReturnTypeDeclarationRule.php b/src/Functions/NoNullableReturnTypeDeclarationRule.php index 0759fdc5..7e0ef3e5 100644 --- a/src/Functions/NoNullableReturnTypeDeclarationRule.php +++ b/src/Functions/NoNullableReturnTypeDeclarationRule.php @@ -46,7 +46,9 @@ public function processNode( )); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString()) + ->build(), ]; } diff --git a/src/Functions/NoParameterWithNullDefaultValueRule.php b/src/Functions/NoParameterWithNullDefaultValueRule.php index 40067482..82e1544a 100644 --- a/src/Functions/NoParameterWithNullDefaultValueRule.php +++ b/src/Functions/NoParameterWithNullDefaultValueRule.php @@ -63,7 +63,9 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString())->build(); + return $ruleErrorBuilder + ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) + ->build(); }, $params)); } } diff --git a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php index 47c7fe23..d6352cd1 100644 --- a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php @@ -59,7 +59,9 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString())->build(); + return $ruleErrorBuilder + ->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString()) + ->build(); }, $params)); } diff --git a/src/Methods/FinalInAbstractClassRule.php b/src/Methods/FinalInAbstractClassRule.php index 7c90aee1..52e22c69 100644 --- a/src/Methods/FinalInAbstractClassRule.php +++ b/src/Methods/FinalInAbstractClassRule.php @@ -86,7 +86,9 @@ public function processNode( )); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::finalInAbstractClass()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::finalInAbstractClass()->toString()) + ->build(), ]; } diff --git a/src/Methods/NoConstructorParameterWithDefaultValueRule.php b/src/Methods/NoConstructorParameterWithDefaultValueRule.php index 7177508c..de00ca50 100644 --- a/src/Methods/NoConstructorParameterWithDefaultValueRule.php +++ b/src/Methods/NoConstructorParameterWithDefaultValueRule.php @@ -65,7 +65,9 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString())->build(); + return $ruleErrorBuilder + ->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString()) + ->build(); }, $params)); } @@ -84,7 +86,9 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString())->build(); + return $ruleErrorBuilder + ->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString()) + ->build(); }, $params)); } } diff --git a/src/Methods/NoNullableReturnTypeDeclarationRule.php b/src/Methods/NoNullableReturnTypeDeclarationRule.php index cb59229b..f9080ac6 100644 --- a/src/Methods/NoNullableReturnTypeDeclarationRule.php +++ b/src/Methods/NoNullableReturnTypeDeclarationRule.php @@ -47,7 +47,9 @@ public function processNode( )); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString()) + ->build(), ]; } @@ -58,7 +60,9 @@ public function processNode( )); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString()) + ->build(), ]; } diff --git a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php index 639441a9..c4bbce03 100644 --- a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php @@ -159,7 +159,9 @@ private static function createError( $classUsedInTypeDeclaration->getName(), )); - return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString())->build(); + return $ruleErrorBuilder + ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) + ->build(); } $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( @@ -170,6 +172,8 @@ private static function createError( $classUsedInTypeDeclaration->getName(), )); - return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString())->build(); + return $ruleErrorBuilder + ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) + ->build(); } } diff --git a/src/Methods/NoParameterWithNullDefaultValueRule.php b/src/Methods/NoParameterWithNullDefaultValueRule.php index d741b5cf..aed0c583 100644 --- a/src/Methods/NoParameterWithNullDefaultValueRule.php +++ b/src/Methods/NoParameterWithNullDefaultValueRule.php @@ -68,7 +68,9 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString())->build(); + return $ruleErrorBuilder + ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) + ->build(); }, $params)); } @@ -88,7 +90,9 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString())->build(); + return $ruleErrorBuilder + ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) + ->build(); }, $params)); } } diff --git a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php index 44e40450..1d33d84d 100644 --- a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php @@ -64,7 +64,9 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString())->build(); + return $ruleErrorBuilder + ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) + ->build(); }, $params)); } @@ -84,7 +86,9 @@ public function processNode( $parameterName, )); - return $ruleErrorBuilder->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString())->build(); + return $ruleErrorBuilder + ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) + ->build(); }, $params)); } diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index cd546874..df8190ed 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -67,7 +67,9 @@ public function processNode( )); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::privateInFinalClass()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::privateInFinalClass()->toString()) + ->build(), ]; } } diff --git a/src/Statements/NoSwitchRule.php b/src/Statements/NoSwitchRule.php index 962f6590..84122460 100644 --- a/src/Statements/NoSwitchRule.php +++ b/src/Statements/NoSwitchRule.php @@ -35,7 +35,9 @@ public function processNode( $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Control structures using switch should not be used.'); return [ - $ruleErrorBuilder->identifier(ErrorIdentifier::noSwitch()->toString())->build(), + $ruleErrorBuilder + ->identifier(ErrorIdentifier::noSwitch()->toString()) + ->build(), ]; } } From 8ad6f7147c773592674e50615d8e2e4224e3d062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 07:55:14 +0100 Subject: [PATCH 12/93] Enhancement: Extract variable --- src/Classes/FinalRule.php | 6 ++++-- src/Classes/NoExtendsRule.php | 12 ++++++++---- .../PHPUnit/Framework/TestCaseWithSuffixRule.php | 6 ++++-- src/Closures/NoParameterWithNullDefaultValueRule.php | 6 ++++-- .../NoParameterWithNullableTypeDeclarationRule.php | 6 ++++-- .../NoNullableReturnTypeDeclarationRule.php | 6 ++++-- .../NoParameterWithNullDefaultValueRule.php | 6 ++++-- .../NoParameterWithNullableTypeDeclarationRule.php | 6 ++++-- src/Methods/FinalInAbstractClassRule.php | 6 ++++-- .../NoConstructorParameterWithDefaultValueRule.php | 12 ++++++++---- src/Methods/NoNullableReturnTypeDeclarationRule.php | 12 ++++++++---- .../NoParameterWithContainerTypeDeclarationRule.php | 12 ++++++++---- src/Methods/NoParameterWithNullDefaultValueRule.php | 12 ++++++++---- .../NoParameterWithNullableTypeDeclarationRule.php | 12 ++++++++---- src/Methods/PrivateInFinalClassRule.php | 6 ++++-- 15 files changed, 84 insertions(+), 42 deletions(-) diff --git a/src/Classes/FinalRule.php b/src/Classes/FinalRule.php index 26119ffa..04196858 100644 --- a/src/Classes/FinalRule.php +++ b/src/Classes/FinalRule.php @@ -93,10 +93,12 @@ public function processNode( return []; } - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( $this->errorMessageTemplate, $node->namespacedName->toString(), - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return [ $ruleErrorBuilder diff --git a/src/Classes/NoExtendsRule.php b/src/Classes/NoExtendsRule.php index 42772e55..b8aa47f3 100644 --- a/src/Classes/NoExtendsRule.php +++ b/src/Classes/NoExtendsRule.php @@ -69,10 +69,12 @@ public function processNode( } if (!isset($node->namespacedName)) { - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Anonymous class is not allowed to extend "%s".', $extendedClassName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return [ $ruleErrorBuilder @@ -81,11 +83,13 @@ public function processNode( ]; } - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Class "%s" is not allowed to extend "%s".', $node->namespacedName->toString(), $extendedClassName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return [ $ruleErrorBuilder diff --git a/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php b/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php index 4e252daa..0abb55ae 100644 --- a/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php +++ b/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php @@ -81,11 +81,13 @@ public function processNode( return []; } - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Class %s extends %s, is concrete, but does not have a Test suffix.', $fullyQualifiedClassName, $extendedPhpunitTestCaseClassName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return [ $ruleErrorBuilder diff --git a/src/Closures/NoParameterWithNullDefaultValueRule.php b/src/Closures/NoParameterWithNullDefaultValueRule.php index 32cb1c62..41bfb75a 100644 --- a/src/Closures/NoParameterWithNullDefaultValueRule.php +++ b/src/Closures/NoParameterWithNullDefaultValueRule.php @@ -55,10 +55,12 @@ public function processNode( /** @var string $parameterName */ $parameterName = $variable->name; - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Closure has parameter $%s with null as default value.', $parameterName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return $ruleErrorBuilder ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) diff --git a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php index 4a9b5827..ab1e0442 100644 --- a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php @@ -51,10 +51,12 @@ public function processNode( /** @var string $parameterName */ $parameterName = $variable->name; - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Closure has parameter $%s with a nullable type declaration.', $parameterName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return $ruleErrorBuilder ->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString()) diff --git a/src/Functions/NoNullableReturnTypeDeclarationRule.php b/src/Functions/NoNullableReturnTypeDeclarationRule.php index 7e0ef3e5..57664786 100644 --- a/src/Functions/NoNullableReturnTypeDeclarationRule.php +++ b/src/Functions/NoNullableReturnTypeDeclarationRule.php @@ -40,10 +40,12 @@ public function processNode( return []; } - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Function %s() has a nullable return type declaration.', $node->namespacedName->toString(), - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return [ $ruleErrorBuilder diff --git a/src/Functions/NoParameterWithNullDefaultValueRule.php b/src/Functions/NoParameterWithNullDefaultValueRule.php index 82e1544a..d79ba38e 100644 --- a/src/Functions/NoParameterWithNullDefaultValueRule.php +++ b/src/Functions/NoParameterWithNullDefaultValueRule.php @@ -57,11 +57,13 @@ public function processNode( /** @var string $parameterName */ $parameterName = $variable->name; - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Function %s() has parameter $%s with null as default value.', $functionName, $parameterName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return $ruleErrorBuilder ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) diff --git a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php index d6352cd1..8c2eaf5e 100644 --- a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php @@ -53,11 +53,13 @@ public function processNode( /** @var string $parameterName */ $parameterName = $variable->name; - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Function %s() has parameter $%s with a nullable type declaration.', $functionName, $parameterName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return $ruleErrorBuilder ->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString()) diff --git a/src/Methods/FinalInAbstractClassRule.php b/src/Methods/FinalInAbstractClassRule.php index 52e22c69..812bbf67 100644 --- a/src/Methods/FinalInAbstractClassRule.php +++ b/src/Methods/FinalInAbstractClassRule.php @@ -79,11 +79,13 @@ public function processNode( return []; } - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Method %s::%s() is not final, but since the containing class is abstract, it should be.', $containingClass->getName(), $node->name->toString(), - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return [ $ruleErrorBuilder diff --git a/src/Methods/NoConstructorParameterWithDefaultValueRule.php b/src/Methods/NoConstructorParameterWithDefaultValueRule.php index de00ca50..07f532a2 100644 --- a/src/Methods/NoConstructorParameterWithDefaultValueRule.php +++ b/src/Methods/NoConstructorParameterWithDefaultValueRule.php @@ -60,10 +60,12 @@ public function processNode( /** @var string $parameterName */ $parameterName = $variable->name; - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Constructor in anonymous class has parameter $%s with default value.', $parameterName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return $ruleErrorBuilder ->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString()) @@ -80,11 +82,13 @@ public function processNode( /** @var string $parameterName */ $parameterName = $variable->name; - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Constructor in %s has parameter $%s with default value.', $className, $parameterName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return $ruleErrorBuilder ->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString()) diff --git a/src/Methods/NoNullableReturnTypeDeclarationRule.php b/src/Methods/NoNullableReturnTypeDeclarationRule.php index f9080ac6..16afb430 100644 --- a/src/Methods/NoNullableReturnTypeDeclarationRule.php +++ b/src/Methods/NoNullableReturnTypeDeclarationRule.php @@ -41,10 +41,12 @@ public function processNode( $classReflection = $scope->getClassReflection(); if ($classReflection->isAnonymous()) { - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Method %s() in anonymous class has a nullable return type declaration.', $node->name->name, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return [ $ruleErrorBuilder @@ -53,11 +55,13 @@ public function processNode( ]; } - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Method %s::%s() has a nullable return type declaration.', $classReflection->getName(), $node->name->name, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return [ $ruleErrorBuilder diff --git a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php index c4bbce03..22cf60a7 100644 --- a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php @@ -152,25 +152,29 @@ private static function createError( Reflection\ClassReflection $classUsedInTypeDeclaration ): Rules\RuleError { if ($classReflection->isAnonymous()) { - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Method %s() in anonymous class has a parameter $%s with a type declaration of %s, but containers should not be injected.', $methodName, $parameterName, $classUsedInTypeDeclaration->getName(), - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return $ruleErrorBuilder ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) ->build(); } - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Method %s::%s() has a parameter $%s with a type declaration of %s, but containers should not be injected.', $classReflection->getName(), $methodName, $parameterName, $classUsedInTypeDeclaration->getName(), - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return $ruleErrorBuilder ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) diff --git a/src/Methods/NoParameterWithNullDefaultValueRule.php b/src/Methods/NoParameterWithNullDefaultValueRule.php index aed0c583..4ced62f8 100644 --- a/src/Methods/NoParameterWithNullDefaultValueRule.php +++ b/src/Methods/NoParameterWithNullDefaultValueRule.php @@ -62,11 +62,13 @@ public function processNode( /** @var string $parameterName */ $parameterName = $variable->name; - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Method %s() in anonymous class has parameter $%s with null as default value.', $methodName, $parameterName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return $ruleErrorBuilder ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) @@ -83,12 +85,14 @@ public function processNode( /** @var string $parameterName */ $parameterName = $variable->name; - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Method %s::%s() has parameter $%s with null as default value.', $className, $methodName, $parameterName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return $ruleErrorBuilder ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) diff --git a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php index 1d33d84d..7e11eab2 100644 --- a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php @@ -58,11 +58,13 @@ public function processNode( /** @var string $parameterName */ $parameterName = $variable->name; - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Method %s() in anonymous class has parameter $%s with a nullable type declaration.', $methodName, $parameterName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return $ruleErrorBuilder ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) @@ -79,12 +81,14 @@ public function processNode( /** @var string $parameterName */ $parameterName = $variable->name; - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Method %s::%s() has parameter $%s with a nullable type declaration.', $className, $methodName, $parameterName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return $ruleErrorBuilder ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index df8190ed..7b61211a 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -60,11 +60,13 @@ public function processNode( } } - $ruleErrorBuilder = Rules\RuleErrorBuilder::message(\sprintf( + $message = \sprintf( 'Method %s::%s() is protected, but since the containing class is final, it can be private.', $containingClass->getName(), $methodName, - )); + ); + + $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); return [ $ruleErrorBuilder From 7533af7541229b7bf76d132cd66a7342be71457f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 07:57:03 +0100 Subject: [PATCH 13/93] Fix: Inline variable --- src/Classes/FinalRule.php | 4 +--- src/Classes/NoExtendsRule.php | 8 ++------ src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php | 4 +--- src/Closures/NoNullableReturnTypeDeclarationRule.php | 4 +--- src/Closures/NoParameterWithNullDefaultValueRule.php | 4 +--- .../NoParameterWithNullableTypeDeclarationRule.php | 4 +--- src/Expressions/NoCompactRule.php | 4 +--- src/Expressions/NoErrorSuppressionRule.php | 4 +--- src/Expressions/NoEvalRule.php | 4 +--- src/Expressions/NoIssetRule.php | 4 +--- src/Files/DeclareStrictTypesRule.php | 4 +--- src/Functions/NoNullableReturnTypeDeclarationRule.php | 4 +--- src/Functions/NoParameterWithNullDefaultValueRule.php | 4 +--- .../NoParameterWithNullableTypeDeclarationRule.php | 4 +--- src/Methods/FinalInAbstractClassRule.php | 4 +--- .../NoConstructorParameterWithDefaultValueRule.php | 8 ++------ src/Methods/NoNullableReturnTypeDeclarationRule.php | 8 ++------ .../NoParameterWithContainerTypeDeclarationRule.php | 8 ++------ src/Methods/NoParameterWithNullDefaultValueRule.php | 8 ++------ .../NoParameterWithNullableTypeDeclarationRule.php | 8 ++------ src/Methods/PrivateInFinalClassRule.php | 4 +--- src/Statements/NoSwitchRule.php | 4 +--- 22 files changed, 28 insertions(+), 84 deletions(-) diff --git a/src/Classes/FinalRule.php b/src/Classes/FinalRule.php index 04196858..144155fb 100644 --- a/src/Classes/FinalRule.php +++ b/src/Classes/FinalRule.php @@ -98,10 +98,8 @@ public function processNode( $node->namespacedName->toString(), ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::final()->toString()) ->build(), ]; diff --git a/src/Classes/NoExtendsRule.php b/src/Classes/NoExtendsRule.php index b8aa47f3..ecbdd4c6 100644 --- a/src/Classes/NoExtendsRule.php +++ b/src/Classes/NoExtendsRule.php @@ -74,10 +74,8 @@ public function processNode( $extendedClassName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noExtends()->toString()) ->build(), ]; @@ -89,10 +87,8 @@ public function processNode( $extendedClassName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noExtends()->toString()) ->build(), ]; diff --git a/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php b/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php index 0abb55ae..9882995d 100644 --- a/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php +++ b/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php @@ -87,10 +87,8 @@ public function processNode( $extendedPhpunitTestCaseClassName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::testCaseWithSuffix()->toString()) ->build(), ]; diff --git a/src/Closures/NoNullableReturnTypeDeclarationRule.php b/src/Closures/NoNullableReturnTypeDeclarationRule.php index a4eba9de..cd58ea0b 100644 --- a/src/Closures/NoNullableReturnTypeDeclarationRule.php +++ b/src/Closures/NoNullableReturnTypeDeclarationRule.php @@ -36,10 +36,8 @@ public function processNode( return []; } - $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Closure has a nullable return type declaration.'); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message('Closure has a nullable return type declaration.') ->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString()) ->build(), ]; diff --git a/src/Closures/NoParameterWithNullDefaultValueRule.php b/src/Closures/NoParameterWithNullDefaultValueRule.php index 41bfb75a..5b4cce55 100644 --- a/src/Closures/NoParameterWithNullDefaultValueRule.php +++ b/src/Closures/NoParameterWithNullDefaultValueRule.php @@ -60,9 +60,7 @@ public function processNode( $parameterName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - - return $ruleErrorBuilder + return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) ->build(); }, $params)); diff --git a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php index ab1e0442..3e7e0edb 100644 --- a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php @@ -56,9 +56,7 @@ public function processNode( $parameterName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - - return $ruleErrorBuilder + return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString()) ->build(); }, $params)); diff --git a/src/Expressions/NoCompactRule.php b/src/Expressions/NoCompactRule.php index 8b126950..f49bec8b 100644 --- a/src/Expressions/NoCompactRule.php +++ b/src/Expressions/NoCompactRule.php @@ -40,10 +40,8 @@ public function processNode( return []; } - $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Function compact() should not be used.'); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message('Function compact() should not be used.') ->identifier(ErrorIdentifier::noCompact()->toString()) ->build(), ]; diff --git a/src/Expressions/NoErrorSuppressionRule.php b/src/Expressions/NoErrorSuppressionRule.php index aeafcafe..642fba3f 100644 --- a/src/Expressions/NoErrorSuppressionRule.php +++ b/src/Expressions/NoErrorSuppressionRule.php @@ -32,10 +32,8 @@ public function processNode( Node $node, Analyser\Scope $scope ): array { - $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Error suppression via "@" should not be used.'); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message('Error suppression via "@" should not be used.') ->identifier(ErrorIdentifier::noErrorSuppression()->toString()) ->build(), ]; diff --git a/src/Expressions/NoEvalRule.php b/src/Expressions/NoEvalRule.php index 75af9872..c3440533 100644 --- a/src/Expressions/NoEvalRule.php +++ b/src/Expressions/NoEvalRule.php @@ -32,10 +32,8 @@ public function processNode( Node $node, Analyser\Scope $scope ): array { - $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Language construct eval() should not be used.'); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message('Language construct eval() should not be used.') ->identifier(ErrorIdentifier::noEval()->toString()) ->build(), ]; diff --git a/src/Expressions/NoIssetRule.php b/src/Expressions/NoIssetRule.php index 12a76df4..ac2ce865 100644 --- a/src/Expressions/NoIssetRule.php +++ b/src/Expressions/NoIssetRule.php @@ -32,10 +32,8 @@ public function processNode( Node $node, Analyser\Scope $scope ): array { - $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Language construct isset() should not be used.'); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message('Language construct isset() should not be used.') ->identifier(ErrorIdentifier::noIsset()->toString()) ->build(), ]; diff --git a/src/Files/DeclareStrictTypesRule.php b/src/Files/DeclareStrictTypesRule.php index 66a74fd3..4d9ccc7e 100644 --- a/src/Files/DeclareStrictTypesRule.php +++ b/src/Files/DeclareStrictTypesRule.php @@ -61,10 +61,8 @@ public function processNode( } } - $ruleErrorBuilder = Rules\RuleErrorBuilder::message('File is missing a "declare(strict_types=1)" declaration.'); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message('File is missing a "declare(strict_types=1)" declaration.') ->identifier(ErrorIdentifier::declareStrictTypes()->toString()) ->build(), ]; diff --git a/src/Functions/NoNullableReturnTypeDeclarationRule.php b/src/Functions/NoNullableReturnTypeDeclarationRule.php index 57664786..a5a50f06 100644 --- a/src/Functions/NoNullableReturnTypeDeclarationRule.php +++ b/src/Functions/NoNullableReturnTypeDeclarationRule.php @@ -45,10 +45,8 @@ public function processNode( $node->namespacedName->toString(), ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString()) ->build(), ]; diff --git a/src/Functions/NoParameterWithNullDefaultValueRule.php b/src/Functions/NoParameterWithNullDefaultValueRule.php index d79ba38e..fdf6e76a 100644 --- a/src/Functions/NoParameterWithNullDefaultValueRule.php +++ b/src/Functions/NoParameterWithNullDefaultValueRule.php @@ -63,9 +63,7 @@ public function processNode( $parameterName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - - return $ruleErrorBuilder + return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) ->build(); }, $params)); diff --git a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php index 8c2eaf5e..a6ed3064 100644 --- a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php @@ -59,9 +59,7 @@ public function processNode( $parameterName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - - return $ruleErrorBuilder + return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString()) ->build(); }, $params)); diff --git a/src/Methods/FinalInAbstractClassRule.php b/src/Methods/FinalInAbstractClassRule.php index 812bbf67..75b2f812 100644 --- a/src/Methods/FinalInAbstractClassRule.php +++ b/src/Methods/FinalInAbstractClassRule.php @@ -85,10 +85,8 @@ public function processNode( $node->name->toString(), ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::finalInAbstractClass()->toString()) ->build(), ]; diff --git a/src/Methods/NoConstructorParameterWithDefaultValueRule.php b/src/Methods/NoConstructorParameterWithDefaultValueRule.php index 07f532a2..ae267888 100644 --- a/src/Methods/NoConstructorParameterWithDefaultValueRule.php +++ b/src/Methods/NoConstructorParameterWithDefaultValueRule.php @@ -65,9 +65,7 @@ public function processNode( $parameterName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - - return $ruleErrorBuilder + return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString()) ->build(); }, $params)); @@ -88,9 +86,7 @@ public function processNode( $parameterName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - - return $ruleErrorBuilder + return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString()) ->build(); }, $params)); diff --git a/src/Methods/NoNullableReturnTypeDeclarationRule.php b/src/Methods/NoNullableReturnTypeDeclarationRule.php index 16afb430..04d26b2c 100644 --- a/src/Methods/NoNullableReturnTypeDeclarationRule.php +++ b/src/Methods/NoNullableReturnTypeDeclarationRule.php @@ -46,10 +46,8 @@ public function processNode( $node->name->name, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString()) ->build(), ]; @@ -61,10 +59,8 @@ public function processNode( $node->name->name, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noNullableReturnTypeDeclaration()->toString()) ->build(), ]; diff --git a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php index 22cf60a7..a237b312 100644 --- a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php @@ -159,9 +159,7 @@ private static function createError( $classUsedInTypeDeclaration->getName(), ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - - return $ruleErrorBuilder + return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) ->build(); } @@ -174,9 +172,7 @@ private static function createError( $classUsedInTypeDeclaration->getName(), ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - - return $ruleErrorBuilder + return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) ->build(); } diff --git a/src/Methods/NoParameterWithNullDefaultValueRule.php b/src/Methods/NoParameterWithNullDefaultValueRule.php index 4ced62f8..828c3707 100644 --- a/src/Methods/NoParameterWithNullDefaultValueRule.php +++ b/src/Methods/NoParameterWithNullDefaultValueRule.php @@ -68,9 +68,7 @@ public function processNode( $parameterName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - - return $ruleErrorBuilder + return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) ->build(); }, $params)); @@ -92,9 +90,7 @@ public function processNode( $parameterName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - - return $ruleErrorBuilder + return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) ->build(); }, $params)); diff --git a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php index 7e11eab2..c93c15cc 100644 --- a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php @@ -64,9 +64,7 @@ public function processNode( $parameterName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - - return $ruleErrorBuilder + return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) ->build(); }, $params)); @@ -88,9 +86,7 @@ public function processNode( $parameterName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - - return $ruleErrorBuilder + return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) ->build(); }, $params)); diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index 7b61211a..12576225 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -66,10 +66,8 @@ public function processNode( $methodName, ); - $ruleErrorBuilder = Rules\RuleErrorBuilder::message($message); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::privateInFinalClass()->toString()) ->build(), ]; diff --git a/src/Statements/NoSwitchRule.php b/src/Statements/NoSwitchRule.php index 84122460..4a52254e 100644 --- a/src/Statements/NoSwitchRule.php +++ b/src/Statements/NoSwitchRule.php @@ -32,10 +32,8 @@ public function processNode( Node $node, Analyser\Scope $scope ): array { - $ruleErrorBuilder = Rules\RuleErrorBuilder::message('Control structures using switch should not be used.'); - return [ - $ruleErrorBuilder + Rules\RuleErrorBuilder::message('Control structures using switch should not be used.') ->identifier(ErrorIdentifier::noSwitch()->toString()) ->build(), ]; From 39f2fe7f1d2dfb7946c5089f8c7ba1e4f9db3894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 07:59:45 +0100 Subject: [PATCH 14/93] Enhancement: Extract variable --- src/Classes/NoExtendsRule.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Classes/NoExtendsRule.php b/src/Classes/NoExtendsRule.php index ecbdd4c6..beb050cf 100644 --- a/src/Classes/NoExtendsRule.php +++ b/src/Classes/NoExtendsRule.php @@ -81,9 +81,11 @@ public function processNode( ]; } + $extendingClassName = $node->namespacedName->toString(); + $message = \sprintf( 'Class "%s" is not allowed to extend "%s".', - $node->namespacedName->toString(), + $extendingClassName, $extendedClassName, ); From c1b59311e5a5d8e02870afdf17f80d9a1ddb8567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:01:25 +0100 Subject: [PATCH 15/93] Fix: Rename variable --- src/Closures/NoParameterWithNullableTypeDeclarationRule.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php index 3e7e0edb..13ea6804 100644 --- a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php @@ -36,11 +36,11 @@ public function processNode( return []; } - $params = \array_filter($node->params, static function (Node\Param $node): bool { + $parametersWithNullableTypeDeclaration = \array_filter($node->params, static function (Node\Param $node): bool { return self::isNullable($node); }); - if (0 === \count($params)) { + if (0 === \count($parametersWithNullableTypeDeclaration)) { return []; } @@ -59,7 +59,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString()) ->build(); - }, $params)); + }, $parametersWithNullableTypeDeclaration)); } private static function isNullable(Node\Param $node): bool From a7add5f39095041241381c46a23871d5cb66c43e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:01:47 +0100 Subject: [PATCH 16/93] Fix: Rename method --- src/Closures/NoParameterWithNullableTypeDeclarationRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php index 13ea6804..17f0f16c 100644 --- a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php @@ -37,7 +37,7 @@ public function processNode( } $parametersWithNullableTypeDeclaration = \array_filter($node->params, static function (Node\Param $node): bool { - return self::isNullable($node); + return self::hasNullableTypeDeclaration($node); }); if (0 === \count($parametersWithNullableTypeDeclaration)) { @@ -62,7 +62,7 @@ public function processNode( }, $parametersWithNullableTypeDeclaration)); } - private static function isNullable(Node\Param $node): bool + private static function hasNullableTypeDeclaration(Node\Param $node): bool { if ($node->type instanceof Node\NullableType) { return true; From 5063caec69e858687b54a1b89360e7246f3ab9c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:02:31 +0100 Subject: [PATCH 17/93] Fix: Rename variable --- src/Closures/NoParameterWithNullDefaultValueRule.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Closures/NoParameterWithNullDefaultValueRule.php b/src/Closures/NoParameterWithNullDefaultValueRule.php index 5b4cce55..157d6407 100644 --- a/src/Closures/NoParameterWithNullDefaultValueRule.php +++ b/src/Closures/NoParameterWithNullDefaultValueRule.php @@ -36,7 +36,7 @@ public function processNode( return []; } - $params = \array_filter($node->params, static function (Node\Param $node): bool { + $parametersWithNullDefaultValue = \array_filter($node->params, static function (Node\Param $node): bool { if (!$node->default instanceof Node\Expr\ConstFetch) { return false; } @@ -44,7 +44,7 @@ public function processNode( return 'null' === $node->default->name->toLowerString(); }); - if (0 === \count($params)) { + if (0 === \count($parametersWithNullDefaultValue)) { return []; } @@ -63,6 +63,6 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) ->build(); - }, $params)); + }, $parametersWithNullDefaultValue)); } } From 55fad99680b64d64e611ef72cc9e39955e595b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:03:03 +0100 Subject: [PATCH 18/93] Fix: Reset earlier --- .../NoParameterWithNullableTypeDeclarationRule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php index 17f0f16c..88d66e4f 100644 --- a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php @@ -36,15 +36,15 @@ public function processNode( return []; } - $parametersWithNullableTypeDeclaration = \array_filter($node->params, static function (Node\Param $node): bool { + $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, static function (Node\Param $node): bool { return self::hasNullableTypeDeclaration($node); - }); + })); if (0 === \count($parametersWithNullableTypeDeclaration)) { return []; } - return \array_values(\array_map(static function (Node\Param $node): Rules\RuleError { + return \array_map(static function (Node\Param $node): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $node->var; @@ -59,7 +59,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString()) ->build(); - }, $parametersWithNullableTypeDeclaration)); + }, $parametersWithNullableTypeDeclaration); } private static function hasNullableTypeDeclaration(Node\Param $node): bool From e1a08959369646d753db564116aac3a1112645a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:03:41 +0100 Subject: [PATCH 19/93] Fix: Reset earlier --- src/Closures/NoParameterWithNullDefaultValueRule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Closures/NoParameterWithNullDefaultValueRule.php b/src/Closures/NoParameterWithNullDefaultValueRule.php index 157d6407..063433e0 100644 --- a/src/Closures/NoParameterWithNullDefaultValueRule.php +++ b/src/Closures/NoParameterWithNullDefaultValueRule.php @@ -36,19 +36,19 @@ public function processNode( return []; } - $parametersWithNullDefaultValue = \array_filter($node->params, static function (Node\Param $node): bool { + $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, static function (Node\Param $node): bool { if (!$node->default instanceof Node\Expr\ConstFetch) { return false; } return 'null' === $node->default->name->toLowerString(); - }); + })); if (0 === \count($parametersWithNullDefaultValue)) { return []; } - return \array_values(\array_map(static function (Node\Param $node): Rules\RuleError { + return \array_map(static function (Node\Param $node): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $node->var; @@ -63,6 +63,6 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) ->build(); - }, $parametersWithNullDefaultValue)); + }, $parametersWithNullDefaultValue); } } From cfa4a8b3e7b8cac16ebaf5adcdedfb0c903c399a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:04:36 +0100 Subject: [PATCH 20/93] Fix: Rename parameter --- src/Closures/NoParameterWithNullableTypeDeclarationRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php index 88d66e4f..79fea00a 100644 --- a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php @@ -44,9 +44,9 @@ public function processNode( return []; } - return \array_map(static function (Node\Param $node): Rules\RuleError { + return \array_map(static function (Node\Param $parameterWithNullableTypeDeclaration): Rules\RuleError { /** @var Node\Expr\Variable $variable */ - $variable = $node->var; + $variable = $parameterWithNullableTypeDeclaration->var; /** @var string $parameterName */ $parameterName = $variable->name; From 09f77852e69331a12db86e0eddd0f2358b3b21d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:05:05 +0100 Subject: [PATCH 21/93] Fix: Rename parameter --- src/Closures/NoParameterWithNullDefaultValueRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Closures/NoParameterWithNullDefaultValueRule.php b/src/Closures/NoParameterWithNullDefaultValueRule.php index 063433e0..9a98aa52 100644 --- a/src/Closures/NoParameterWithNullDefaultValueRule.php +++ b/src/Closures/NoParameterWithNullDefaultValueRule.php @@ -48,9 +48,9 @@ public function processNode( return []; } - return \array_map(static function (Node\Param $node): Rules\RuleError { + return \array_map(static function (Node\Param $parameterWithNullDefaultValue): Rules\RuleError { /** @var Node\Expr\Variable $variable */ - $variable = $node->var; + $variable = $parameterWithNullDefaultValue->var; /** @var string $parameterName */ $parameterName = $variable->name; From bcb1b2dcebc875cee481294984450a6d1f3ff7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:06:56 +0100 Subject: [PATCH 22/93] Fix: Rename method --- src/Closures/NoNullableReturnTypeDeclarationRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Closures/NoNullableReturnTypeDeclarationRule.php b/src/Closures/NoNullableReturnTypeDeclarationRule.php index cd58ea0b..340f42c2 100644 --- a/src/Closures/NoNullableReturnTypeDeclarationRule.php +++ b/src/Closures/NoNullableReturnTypeDeclarationRule.php @@ -32,7 +32,7 @@ public function processNode( Node $node, Analyser\Scope $scope ): array { - if (!self::hasNullableReturnType($node)) { + if (!self::hasNullableReturnTypeDeclaration($node)) { return []; } @@ -43,7 +43,7 @@ public function processNode( ]; } - private static function hasNullableReturnType(Node\Expr\Closure $node): bool + private static function hasNullableReturnTypeDeclaration(Node\Expr\Closure $node): bool { $returnType = $node->getReturnType(); From 68b55f66cb31ec308ab87b60b7296b12392e927a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:08:47 +0100 Subject: [PATCH 23/93] Enhancement: Extract method --- .../NoParameterWithNullDefaultValueRule.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Closures/NoParameterWithNullDefaultValueRule.php b/src/Closures/NoParameterWithNullDefaultValueRule.php index 9a98aa52..aec53380 100644 --- a/src/Closures/NoParameterWithNullDefaultValueRule.php +++ b/src/Closures/NoParameterWithNullDefaultValueRule.php @@ -37,11 +37,7 @@ public function processNode( } $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, static function (Node\Param $node): bool { - if (!$node->default instanceof Node\Expr\ConstFetch) { - return false; - } - - return 'null' === $node->default->name->toLowerString(); + return self::hasNullDefaultValue($node); })); if (0 === \count($parametersWithNullDefaultValue)) { @@ -65,4 +61,13 @@ public function processNode( ->build(); }, $parametersWithNullDefaultValue); } + + private static function hasNullDefaultValue(Node\Param $node): bool + { + if (!$node->default instanceof Node\Expr\ConstFetch) { + return false; + } + + return 'null' === $node->default->name->toLowerString(); + } } From e4fc3cc9e13c0246298fbde4134941dd71376d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:09:36 +0100 Subject: [PATCH 24/93] Fix: Rename method --- src/Functions/NoParameterWithNullableTypeDeclarationRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php index a6ed3064..65b0d1d4 100644 --- a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php @@ -37,7 +37,7 @@ public function processNode( } $params = \array_filter($node->params, static function (Node\Param $node): bool { - return self::isNullable($node); + return self::hasNullableTypeDeclration($node); }); if (0 === \count($params)) { @@ -65,7 +65,7 @@ public function processNode( }, $params)); } - private static function isNullable(Node\Param $node): bool + private static function hasNullableTypeDeclration(Node\Param $node): bool { if ($node->type instanceof Node\NullableType) { return true; From 19357c0e1338a06a7b7923d62ec8c131d0c4e5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:10:31 +0100 Subject: [PATCH 25/93] Enhancement: Extract method --- .../NoParameterWithNullDefaultValueRule.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Functions/NoParameterWithNullDefaultValueRule.php b/src/Functions/NoParameterWithNullDefaultValueRule.php index fdf6e76a..fae24d23 100644 --- a/src/Functions/NoParameterWithNullDefaultValueRule.php +++ b/src/Functions/NoParameterWithNullDefaultValueRule.php @@ -37,11 +37,7 @@ public function processNode( } $params = \array_filter($node->params, static function (Node\Param $node): bool { - if (!$node->default instanceof Node\Expr\ConstFetch) { - return false; - } - - return 'null' === $node->default->name->toLowerString(); + return self::hasNullDefaultValue($node); }); if (0 === \count($params)) { @@ -68,4 +64,13 @@ public function processNode( ->build(); }, $params)); } + + private static function hasNullDefaultValue(Node\Param $node): bool + { + if (!$node->default instanceof Node\Expr\ConstFetch) { + return false; + } + + return 'null' === $node->default->name->toLowerString(); + } } From c4873f74163523a2386894090543bc913d545236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:11:27 +0100 Subject: [PATCH 26/93] Fix: Rename variable --- .../NoParameterWithNullableTypeDeclarationRule.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php index 65b0d1d4..7a0ea9d4 100644 --- a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php @@ -36,11 +36,11 @@ public function processNode( return []; } - $params = \array_filter($node->params, static function (Node\Param $node): bool { + $parametersWithNullableTypeDeclaration = \array_filter($node->params, static function (Node\Param $node): bool { return self::hasNullableTypeDeclration($node); }); - if (0 === \count($params)) { + if (0 === \count($parametersWithNullableTypeDeclaration)) { return []; } @@ -62,7 +62,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString()) ->build(); - }, $params)); + }, $parametersWithNullableTypeDeclaration)); } private static function hasNullableTypeDeclration(Node\Param $node): bool From a6241b8dc86084b9696653943e1ee39009297344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:11:43 +0100 Subject: [PATCH 27/93] Fix: Rename parameter --- src/Functions/NoParameterWithNullableTypeDeclarationRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php index 7a0ea9d4..c985a39a 100644 --- a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php @@ -46,9 +46,9 @@ public function processNode( $functionName = $node->namespacedName; - return \array_values(\array_map(static function (Node\Param $node) use ($functionName): Rules\RuleError { + return \array_values(\array_map(static function (Node\Param $parameterWithNullableTypeDeclaration) use ($functionName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ - $variable = $node->var; + $variable = $parameterWithNullableTypeDeclaration->var; /** @var string $parameterName */ $parameterName = $variable->name; From a3f0793a62eab27acb04b43718303794c66a1477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:12:12 +0100 Subject: [PATCH 28/93] Fix: Reset earlier --- .../NoParameterWithNullableTypeDeclarationRule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php index c985a39a..189b9ca8 100644 --- a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php @@ -36,9 +36,9 @@ public function processNode( return []; } - $parametersWithNullableTypeDeclaration = \array_filter($node->params, static function (Node\Param $node): bool { + $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, static function (Node\Param $node): bool { return self::hasNullableTypeDeclration($node); - }); + })); if (0 === \count($parametersWithNullableTypeDeclaration)) { return []; @@ -46,7 +46,7 @@ public function processNode( $functionName = $node->namespacedName; - return \array_values(\array_map(static function (Node\Param $parameterWithNullableTypeDeclaration) use ($functionName): Rules\RuleError { + return \array_map(static function (Node\Param $parameterWithNullableTypeDeclaration) use ($functionName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $parameterWithNullableTypeDeclaration->var; @@ -62,7 +62,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullableTypeDeclaration()->toString()) ->build(); - }, $parametersWithNullableTypeDeclaration)); + }, $parametersWithNullableTypeDeclaration); } private static function hasNullableTypeDeclration(Node\Param $node): bool From c7dd4878de1e9b84f304ca3d64c60f3b32ceba20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:12:34 +0100 Subject: [PATCH 29/93] Fix: Typo --- src/Functions/NoParameterWithNullableTypeDeclarationRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php index 189b9ca8..32fde9cc 100644 --- a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php @@ -37,7 +37,7 @@ public function processNode( } $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, static function (Node\Param $node): bool { - return self::hasNullableTypeDeclration($node); + return self::hasNullableTypeDeclaration($node); })); if (0 === \count($parametersWithNullableTypeDeclaration)) { @@ -65,7 +65,7 @@ public function processNode( }, $parametersWithNullableTypeDeclaration); } - private static function hasNullableTypeDeclration(Node\Param $node): bool + private static function hasNullableTypeDeclaration(Node\Param $node): bool { if ($node->type instanceof Node\NullableType) { return true; From e00141359eef4a4bce5ad54f4e0235caa7cf98b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:13:09 +0100 Subject: [PATCH 30/93] Fix: Rename variable --- src/Functions/NoParameterWithNullDefaultValueRule.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Functions/NoParameterWithNullDefaultValueRule.php b/src/Functions/NoParameterWithNullDefaultValueRule.php index fae24d23..863d9c80 100644 --- a/src/Functions/NoParameterWithNullDefaultValueRule.php +++ b/src/Functions/NoParameterWithNullDefaultValueRule.php @@ -36,11 +36,11 @@ public function processNode( return []; } - $params = \array_filter($node->params, static function (Node\Param $node): bool { + $parametersWithNullDefaultValue = \array_filter($node->params, static function (Node\Param $node): bool { return self::hasNullDefaultValue($node); }); - if (0 === \count($params)) { + if (0 === \count($parametersWithNullDefaultValue)) { return []; } @@ -62,7 +62,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) ->build(); - }, $params)); + }, $parametersWithNullDefaultValue)); } private static function hasNullDefaultValue(Node\Param $node): bool From fa7816ed3a108b80914d42613e8fbfd7993a4735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:13:26 +0100 Subject: [PATCH 31/93] Fix: Rename parameter --- src/Functions/NoParameterWithNullDefaultValueRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Functions/NoParameterWithNullDefaultValueRule.php b/src/Functions/NoParameterWithNullDefaultValueRule.php index 863d9c80..3026b7fb 100644 --- a/src/Functions/NoParameterWithNullDefaultValueRule.php +++ b/src/Functions/NoParameterWithNullDefaultValueRule.php @@ -46,9 +46,9 @@ public function processNode( $functionName = $node->namespacedName; - return \array_values(\array_map(static function (Node\Param $node) use ($functionName): Rules\RuleError { + return \array_values(\array_map(static function (Node\Param $parameterWithNullDefaultValue) use ($functionName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ - $variable = $node->var; + $variable = $parameterWithNullDefaultValue->var; /** @var string $parameterName */ $parameterName = $variable->name; From 21b40096e8b0c937100cdbcd77b4cbfa4964dbaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:14:40 +0100 Subject: [PATCH 32/93] Fix: Reset earlier --- src/Functions/NoParameterWithNullDefaultValueRule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Functions/NoParameterWithNullDefaultValueRule.php b/src/Functions/NoParameterWithNullDefaultValueRule.php index 3026b7fb..12eac56d 100644 --- a/src/Functions/NoParameterWithNullDefaultValueRule.php +++ b/src/Functions/NoParameterWithNullDefaultValueRule.php @@ -36,9 +36,9 @@ public function processNode( return []; } - $parametersWithNullDefaultValue = \array_filter($node->params, static function (Node\Param $node): bool { + $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, static function (Node\Param $node): bool { return self::hasNullDefaultValue($node); - }); + })); if (0 === \count($parametersWithNullDefaultValue)) { return []; @@ -46,7 +46,7 @@ public function processNode( $functionName = $node->namespacedName; - return \array_values(\array_map(static function (Node\Param $parameterWithNullDefaultValue) use ($functionName): Rules\RuleError { + return \array_map(static function (Node\Param $parameterWithNullDefaultValue) use ($functionName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $parameterWithNullDefaultValue->var; @@ -62,7 +62,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) ->build(); - }, $parametersWithNullDefaultValue)); + }, $parametersWithNullDefaultValue); } private static function hasNullDefaultValue(Node\Param $node): bool From 5f4d0960fa344b18db9f1d6a172241bd5aa114e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:19:23 +0100 Subject: [PATCH 33/93] Fix: Rename parameters --- src/Closures/NoNullableReturnTypeDeclarationRule.php | 4 ++-- src/Closures/NoParameterWithNullDefaultValueRule.php | 6 +++--- .../NoParameterWithNullableTypeDeclarationRule.php | 8 ++++---- src/Functions/NoNullableReturnTypeDeclarationRule.php | 4 ++-- src/Functions/NoParameterWithNullDefaultValueRule.php | 6 +++--- .../NoParameterWithNullableTypeDeclarationRule.php | 8 ++++---- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Closures/NoNullableReturnTypeDeclarationRule.php b/src/Closures/NoNullableReturnTypeDeclarationRule.php index 340f42c2..87a188b3 100644 --- a/src/Closures/NoNullableReturnTypeDeclarationRule.php +++ b/src/Closures/NoNullableReturnTypeDeclarationRule.php @@ -43,9 +43,9 @@ public function processNode( ]; } - private static function hasNullableReturnTypeDeclaration(Node\Expr\Closure $node): bool + private static function hasNullableReturnTypeDeclaration(Node\Expr\Closure $closure): bool { - $returnType = $node->getReturnType(); + $returnType = $closure->getReturnType(); if ($returnType instanceof Node\NullableType) { return true; diff --git a/src/Closures/NoParameterWithNullDefaultValueRule.php b/src/Closures/NoParameterWithNullDefaultValueRule.php index aec53380..0b59f95b 100644 --- a/src/Closures/NoParameterWithNullDefaultValueRule.php +++ b/src/Closures/NoParameterWithNullDefaultValueRule.php @@ -62,12 +62,12 @@ public function processNode( }, $parametersWithNullDefaultValue); } - private static function hasNullDefaultValue(Node\Param $node): bool + private static function hasNullDefaultValue(Node\Param $parameter): bool { - if (!$node->default instanceof Node\Expr\ConstFetch) { + if (!$parameter->default instanceof Node\Expr\ConstFetch) { return false; } - return 'null' === $node->default->name->toLowerString(); + return 'null' === $parameter->default->name->toLowerString(); } } diff --git a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php index 79fea00a..7c8259da 100644 --- a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php @@ -62,14 +62,14 @@ public function processNode( }, $parametersWithNullableTypeDeclaration); } - private static function hasNullableTypeDeclaration(Node\Param $node): bool + private static function hasNullableTypeDeclaration(Node\Param $parameter): bool { - if ($node->type instanceof Node\NullableType) { + if ($parameter->type instanceof Node\NullableType) { return true; } - if ($node->type instanceof Node\UnionType) { - foreach ($node->type->types as $type) { + if ($parameter->type instanceof Node\UnionType) { + foreach ($parameter->type->types as $type) { if (!$type instanceof Node\Identifier) { continue; } diff --git a/src/Functions/NoNullableReturnTypeDeclarationRule.php b/src/Functions/NoNullableReturnTypeDeclarationRule.php index a5a50f06..86235ec5 100644 --- a/src/Functions/NoNullableReturnTypeDeclarationRule.php +++ b/src/Functions/NoNullableReturnTypeDeclarationRule.php @@ -52,9 +52,9 @@ public function processNode( ]; } - private static function hasNullableReturnType(Node\Stmt\Function_ $node): bool + private static function hasNullableReturnType(Node\Stmt\Function_ $function): bool { - $returnType = $node->getReturnType(); + $returnType = $function->getReturnType(); if ($returnType instanceof Node\NullableType) { return true; diff --git a/src/Functions/NoParameterWithNullDefaultValueRule.php b/src/Functions/NoParameterWithNullDefaultValueRule.php index 12eac56d..3b3942ab 100644 --- a/src/Functions/NoParameterWithNullDefaultValueRule.php +++ b/src/Functions/NoParameterWithNullDefaultValueRule.php @@ -65,12 +65,12 @@ public function processNode( }, $parametersWithNullDefaultValue); } - private static function hasNullDefaultValue(Node\Param $node): bool + private static function hasNullDefaultValue(Node\Param $parameter): bool { - if (!$node->default instanceof Node\Expr\ConstFetch) { + if (!$parameter->default instanceof Node\Expr\ConstFetch) { return false; } - return 'null' === $node->default->name->toLowerString(); + return 'null' === $parameter->default->name->toLowerString(); } } diff --git a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php index 32fde9cc..bcce70f4 100644 --- a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php @@ -65,14 +65,14 @@ public function processNode( }, $parametersWithNullableTypeDeclaration); } - private static function hasNullableTypeDeclaration(Node\Param $node): bool + private static function hasNullableTypeDeclaration(Node\Param $parameter): bool { - if ($node->type instanceof Node\NullableType) { + if ($parameter->type instanceof Node\NullableType) { return true; } - if ($node->type instanceof Node\UnionType) { - foreach ($node->type->types as $type) { + if ($parameter->type instanceof Node\UnionType) { + foreach ($parameter->type->types as $type) { if (!$type instanceof Node\Identifier) { continue; } From 74efa3e279c25fddf6d8d1242e96a94008e44b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:21:36 +0100 Subject: [PATCH 34/93] Enhancement: Extract method --- src/Methods/NoConstructorParameterWithDefaultValueRule.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Methods/NoConstructorParameterWithDefaultValueRule.php b/src/Methods/NoConstructorParameterWithDefaultValueRule.php index ae267888..6d539b09 100644 --- a/src/Methods/NoConstructorParameterWithDefaultValueRule.php +++ b/src/Methods/NoConstructorParameterWithDefaultValueRule.php @@ -42,7 +42,7 @@ public function processNode( } $params = \array_filter($node->params, static function (Node\Param $node): bool { - return null !== $node->default; + return self::hasNullDefaultValue($node); }); if (0 === \count($params)) { @@ -91,4 +91,9 @@ public function processNode( ->build(); }, $params)); } + + private static function hasNullDefaultValue(Node\Param $node): bool + { + return null !== $node->default; + } } From 10756bbb7ef82489a8cbee73f80dfbd6ca89f2be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:22:08 +0100 Subject: [PATCH 35/93] Fix: Rename parameter --- src/Methods/NoConstructorParameterWithDefaultValueRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Methods/NoConstructorParameterWithDefaultValueRule.php b/src/Methods/NoConstructorParameterWithDefaultValueRule.php index 6d539b09..cd6f4e81 100644 --- a/src/Methods/NoConstructorParameterWithDefaultValueRule.php +++ b/src/Methods/NoConstructorParameterWithDefaultValueRule.php @@ -92,8 +92,8 @@ public function processNode( }, $params)); } - private static function hasNullDefaultValue(Node\Param $node): bool + private static function hasNullDefaultValue(Node\Param $parameter): bool { - return null !== $node->default; + return null !== $parameter->default; } } From c9acb19cd1592ae30f4b37e2bdd947c8d15d4903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:22:59 +0100 Subject: [PATCH 36/93] Fix: Rename method --- src/Methods/NoConstructorParameterWithDefaultValueRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Methods/NoConstructorParameterWithDefaultValueRule.php b/src/Methods/NoConstructorParameterWithDefaultValueRule.php index cd6f4e81..97aa1d90 100644 --- a/src/Methods/NoConstructorParameterWithDefaultValueRule.php +++ b/src/Methods/NoConstructorParameterWithDefaultValueRule.php @@ -42,7 +42,7 @@ public function processNode( } $params = \array_filter($node->params, static function (Node\Param $node): bool { - return self::hasNullDefaultValue($node); + return self::hasDefaultValue($node); }); if (0 === \count($params)) { @@ -92,7 +92,7 @@ public function processNode( }, $params)); } - private static function hasNullDefaultValue(Node\Param $parameter): bool + private static function hasDefaultValue(Node\Param $parameter): bool { return null !== $parameter->default; } From f5144c579d033ad73c1a4495556fb166869be249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:24:46 +0100 Subject: [PATCH 37/93] Fix: Rename parameter --- src/Closures/NoParameterWithNullDefaultValueRule.php | 4 ++-- src/Closures/NoParameterWithNullableTypeDeclarationRule.php | 4 ++-- src/Functions/NoParameterWithNullDefaultValueRule.php | 4 ++-- src/Functions/NoParameterWithNullableTypeDeclarationRule.php | 4 ++-- src/Methods/NoConstructorParameterWithDefaultValueRule.php | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Closures/NoParameterWithNullDefaultValueRule.php b/src/Closures/NoParameterWithNullDefaultValueRule.php index 0b59f95b..144053b0 100644 --- a/src/Closures/NoParameterWithNullDefaultValueRule.php +++ b/src/Closures/NoParameterWithNullDefaultValueRule.php @@ -36,8 +36,8 @@ public function processNode( return []; } - $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, static function (Node\Param $node): bool { - return self::hasNullDefaultValue($node); + $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { + return self::hasNullDefaultValue($parameter); })); if (0 === \count($parametersWithNullDefaultValue)) { diff --git a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php index 7c8259da..07acfbab 100644 --- a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php @@ -36,8 +36,8 @@ public function processNode( return []; } - $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, static function (Node\Param $node): bool { - return self::hasNullableTypeDeclaration($node); + $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { + return self::hasNullableTypeDeclaration($parameter); })); if (0 === \count($parametersWithNullableTypeDeclaration)) { diff --git a/src/Functions/NoParameterWithNullDefaultValueRule.php b/src/Functions/NoParameterWithNullDefaultValueRule.php index 3b3942ab..7cb5ee0e 100644 --- a/src/Functions/NoParameterWithNullDefaultValueRule.php +++ b/src/Functions/NoParameterWithNullDefaultValueRule.php @@ -36,8 +36,8 @@ public function processNode( return []; } - $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, static function (Node\Param $node): bool { - return self::hasNullDefaultValue($node); + $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { + return self::hasNullDefaultValue($parameter); })); if (0 === \count($parametersWithNullDefaultValue)) { diff --git a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php index bcce70f4..c15e88d6 100644 --- a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php @@ -36,8 +36,8 @@ public function processNode( return []; } - $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, static function (Node\Param $node): bool { - return self::hasNullableTypeDeclaration($node); + $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { + return self::hasNullableTypeDeclaration($parameter); })); if (0 === \count($parametersWithNullableTypeDeclaration)) { diff --git a/src/Methods/NoConstructorParameterWithDefaultValueRule.php b/src/Methods/NoConstructorParameterWithDefaultValueRule.php index 97aa1d90..377f283e 100644 --- a/src/Methods/NoConstructorParameterWithDefaultValueRule.php +++ b/src/Methods/NoConstructorParameterWithDefaultValueRule.php @@ -41,8 +41,8 @@ public function processNode( return []; } - $params = \array_filter($node->params, static function (Node\Param $node): bool { - return self::hasDefaultValue($node); + $params = \array_filter($node->params, static function (Node\Param $parameter): bool { + return self::hasDefaultValue($parameter); }); if (0 === \count($params)) { From ce22fa274f5ad82f375a1b5b732e84e617df4847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:25:28 +0100 Subject: [PATCH 38/93] Fix: Reset earlier --- .../NoConstructorParameterWithDefaultValueRule.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Methods/NoConstructorParameterWithDefaultValueRule.php b/src/Methods/NoConstructorParameterWithDefaultValueRule.php index 377f283e..df9b5bc9 100644 --- a/src/Methods/NoConstructorParameterWithDefaultValueRule.php +++ b/src/Methods/NoConstructorParameterWithDefaultValueRule.php @@ -41,9 +41,9 @@ public function processNode( return []; } - $params = \array_filter($node->params, static function (Node\Param $parameter): bool { + $params = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { return self::hasDefaultValue($parameter); - }); + })); if (0 === \count($params)) { return []; @@ -53,7 +53,7 @@ public function processNode( $classReflection = $scope->getClassReflection(); if ($classReflection->isAnonymous()) { - return \array_values(\array_map(static function (Node\Param $node): Rules\RuleError { + return \array_map(static function (Node\Param $node): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $node->var; @@ -68,12 +68,12 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString()) ->build(); - }, $params)); + }, $params); } $className = $classReflection->getName(); - return \array_values(\array_map(static function (Node\Param $node) use ($className): Rules\RuleError { + return \array_map(static function (Node\Param $node) use ($className): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $node->var; @@ -89,7 +89,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString()) ->build(); - }, $params)); + }, $params); } private static function hasDefaultValue(Node\Param $parameter): bool From d6250d55cfb4b02882885c287ffe759cde2a9874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:27:35 +0100 Subject: [PATCH 39/93] Fix: Rename variable --- .../NoConstructorParameterWithDefaultValueRule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Methods/NoConstructorParameterWithDefaultValueRule.php b/src/Methods/NoConstructorParameterWithDefaultValueRule.php index df9b5bc9..bd8b1d3d 100644 --- a/src/Methods/NoConstructorParameterWithDefaultValueRule.php +++ b/src/Methods/NoConstructorParameterWithDefaultValueRule.php @@ -41,11 +41,11 @@ public function processNode( return []; } - $params = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { + $parametersWithDefaultValue = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { return self::hasDefaultValue($parameter); })); - if (0 === \count($params)) { + if (0 === \count($parametersWithDefaultValue)) { return []; } @@ -68,7 +68,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString()) ->build(); - }, $params); + }, $parametersWithDefaultValue); } $className = $classReflection->getName(); @@ -89,7 +89,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noConstructorParameterWithDefaultValue()->toString()) ->build(); - }, $params); + }, $parametersWithDefaultValue); } private static function hasDefaultValue(Node\Param $parameter): bool From 514a9b2ba85de9573de17be67e1af062d7737db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:28:03 +0100 Subject: [PATCH 40/93] Fix: Rename parameter --- .../NoConstructorParameterWithDefaultValueRule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Methods/NoConstructorParameterWithDefaultValueRule.php b/src/Methods/NoConstructorParameterWithDefaultValueRule.php index bd8b1d3d..233343e5 100644 --- a/src/Methods/NoConstructorParameterWithDefaultValueRule.php +++ b/src/Methods/NoConstructorParameterWithDefaultValueRule.php @@ -53,9 +53,9 @@ public function processNode( $classReflection = $scope->getClassReflection(); if ($classReflection->isAnonymous()) { - return \array_map(static function (Node\Param $node): Rules\RuleError { + return \array_map(static function (Node\Param $parameterWithDefaultValue): Rules\RuleError { /** @var Node\Expr\Variable $variable */ - $variable = $node->var; + $variable = $parameterWithDefaultValue->var; /** @var string $parameterName */ $parameterName = $variable->name; @@ -73,9 +73,9 @@ public function processNode( $className = $classReflection->getName(); - return \array_map(static function (Node\Param $node) use ($className): Rules\RuleError { + return \array_map(static function (Node\Param $parameterWithDefaultValue) use ($className): Rules\RuleError { /** @var Node\Expr\Variable $variable */ - $variable = $node->var; + $variable = $parameterWithDefaultValue->var; /** @var string $parameterName */ $parameterName = $variable->name; From 246ebcb3ec3eec1fb21b06050939dfcb01aa8254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:29:16 +0100 Subject: [PATCH 41/93] Fix: Rename parameter --- src/Methods/NoNullableReturnTypeDeclarationRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Methods/NoNullableReturnTypeDeclarationRule.php b/src/Methods/NoNullableReturnTypeDeclarationRule.php index 04d26b2c..570254f7 100644 --- a/src/Methods/NoNullableReturnTypeDeclarationRule.php +++ b/src/Methods/NoNullableReturnTypeDeclarationRule.php @@ -66,9 +66,9 @@ public function processNode( ]; } - private static function hasNullableReturnType(Node\Stmt\ClassMethod $node): bool + private static function hasNullableReturnType(Node\Stmt\ClassMethod $method): bool { - $returnType = $node->getReturnType(); + $returnType = $method->getReturnType(); if ($returnType instanceof Node\NullableType) { return true; From 4b302a251ef2ccefacc495baef89f3915771279b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:31:11 +0100 Subject: [PATCH 42/93] Fix: Rename variable --- .../NoParameterWithNullableTypeDeclarationRule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php index c93c15cc..b8b68079 100644 --- a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php @@ -37,11 +37,11 @@ public function processNode( return []; } - $params = \array_filter($node->params, static function (Node\Param $node): bool { + $parametersWithNullableTypeDeclaration = \array_filter($node->params, static function (Node\Param $node): bool { return self::isNullable($node); }); - if (0 === \count($params)) { + if (0 === \count($parametersWithNullableTypeDeclaration)) { return []; } @@ -67,7 +67,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) ->build(); - }, $params)); + }, $parametersWithNullableTypeDeclaration)); } $className = $classReflection->getName(); @@ -89,7 +89,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) ->build(); - }, $params)); + }, $parametersWithNullableTypeDeclaration)); } private static function isNullable(Node\Param $node): bool From 0cec81c902563064347e38de86aed9ff2118b3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:31:26 +0100 Subject: [PATCH 43/93] Fix: Rename parameter --- src/Methods/NoParameterWithNullableTypeDeclarationRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php index b8b68079..509a9f9e 100644 --- a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php @@ -37,8 +37,8 @@ public function processNode( return []; } - $parametersWithNullableTypeDeclaration = \array_filter($node->params, static function (Node\Param $node): bool { - return self::isNullable($node); + $parametersWithNullableTypeDeclaration = \array_filter($node->params, static function (Node\Param $parameter): bool { + return self::isNullable($parameter); }); if (0 === \count($parametersWithNullableTypeDeclaration)) { From d4fd2280d3794ceb27a85c3589e90cbb29fe4f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:31:58 +0100 Subject: [PATCH 44/93] Fix: Rename method --- src/Methods/NoParameterWithNullableTypeDeclarationRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php index 509a9f9e..879b1fd6 100644 --- a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php @@ -38,7 +38,7 @@ public function processNode( } $parametersWithNullableTypeDeclaration = \array_filter($node->params, static function (Node\Param $parameter): bool { - return self::isNullable($parameter); + return self::hasNullableTypeDeclaration($parameter); }); if (0 === \count($parametersWithNullableTypeDeclaration)) { @@ -92,7 +92,7 @@ public function processNode( }, $parametersWithNullableTypeDeclaration)); } - private static function isNullable(Node\Param $node): bool + private static function hasNullableTypeDeclaration(Node\Param $node): bool { if ($node->type instanceof Node\NullableType) { return true; From 4b2f92de7f96b685cf1c9d9c3ef5cba455818f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:32:39 +0100 Subject: [PATCH 45/93] Fix: Reset earlier --- .../NoParameterWithNullableTypeDeclarationRule.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php index 879b1fd6..d6407661 100644 --- a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php @@ -37,9 +37,9 @@ public function processNode( return []; } - $parametersWithNullableTypeDeclaration = \array_filter($node->params, static function (Node\Param $parameter): bool { + $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { return self::hasNullableTypeDeclaration($parameter); - }); + })); if (0 === \count($parametersWithNullableTypeDeclaration)) { return []; @@ -51,7 +51,7 @@ public function processNode( $classReflection = $scope->getClassReflection(); if ($classReflection->isAnonymous()) { - return \array_values(\array_map(static function (Node\Param $node) use ($methodName): Rules\RuleError { + return \array_map(static function (Node\Param $node) use ($methodName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $node->var; @@ -67,12 +67,12 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) ->build(); - }, $parametersWithNullableTypeDeclaration)); + }, $parametersWithNullableTypeDeclaration); } $className = $classReflection->getName(); - return \array_values(\array_map(static function (Node\Param $node) use ($className, $methodName): Rules\RuleError { + return \array_map(static function (Node\Param $node) use ($className, $methodName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $node->var; @@ -89,7 +89,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithContainerTypeDeclaration()->toString()) ->build(); - }, $parametersWithNullableTypeDeclaration)); + }, $parametersWithNullableTypeDeclaration); } private static function hasNullableTypeDeclaration(Node\Param $node): bool From 5eec667fa5d8d70ece61fc1def449b08d1370ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 08:32:56 +0100 Subject: [PATCH 46/93] Fix: Rename parameter --- .../NoParameterWithNullableTypeDeclarationRule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php index d6407661..48eaed89 100644 --- a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php @@ -92,14 +92,14 @@ public function processNode( }, $parametersWithNullableTypeDeclaration); } - private static function hasNullableTypeDeclaration(Node\Param $node): bool + private static function hasNullableTypeDeclaration(Node\Param $parameter): bool { - if ($node->type instanceof Node\NullableType) { + if ($parameter->type instanceof Node\NullableType) { return true; } - if ($node->type instanceof Node\UnionType) { - foreach ($node->type->types as $type) { + if ($parameter->type instanceof Node\UnionType) { + foreach ($parameter->type->types as $type) { if (!$type instanceof Node\Identifier) { continue; } From 20aabf41002a8e9b0e7b54dd62544747e8b8c902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 09:39:46 +0100 Subject: [PATCH 47/93] Fix: Rename parameter --- .../NoParameterWithNullableTypeDeclarationRule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php index 48eaed89..9f260fde 100644 --- a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php @@ -51,9 +51,9 @@ public function processNode( $classReflection = $scope->getClassReflection(); if ($classReflection->isAnonymous()) { - return \array_map(static function (Node\Param $node) use ($methodName): Rules\RuleError { + return \array_map(static function (Node\Param $parameterWithNullableTypeDeclaration) use ($methodName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ - $variable = $node->var; + $variable = $parameterWithNullableTypeDeclaration->var; /** @var string $parameterName */ $parameterName = $variable->name; @@ -72,9 +72,9 @@ public function processNode( $className = $classReflection->getName(); - return \array_map(static function (Node\Param $node) use ($className, $methodName): Rules\RuleError { + return \array_map(static function (Node\Param $parameterWithNullableTypeDeclaration) use ($className, $methodName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ - $variable = $node->var; + $variable = $parameterWithNullableTypeDeclaration->var; /** @var string $parameterName */ $parameterName = $variable->name; From 2b1d14fd8033c0ef6c735e9144e7462a312b457c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 09:41:18 +0100 Subject: [PATCH 48/93] Enhancement: Extract method --- .../NoParameterWithNullDefaultValueRule.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Methods/NoParameterWithNullDefaultValueRule.php b/src/Methods/NoParameterWithNullDefaultValueRule.php index 828c3707..13c98ac0 100644 --- a/src/Methods/NoParameterWithNullDefaultValueRule.php +++ b/src/Methods/NoParameterWithNullDefaultValueRule.php @@ -38,11 +38,7 @@ public function processNode( } $params = \array_filter($node->params, static function (Node\Param $node): bool { - if (!$node->default instanceof Node\Expr\ConstFetch) { - return false; - } - - return 'null' === $node->default->name->toLowerString(); + return self::hasNullDefaultValue($node); }); if (0 === \count($params)) { @@ -95,4 +91,13 @@ public function processNode( ->build(); }, $params)); } + + private static function hasNullDefaultValue(Node\Param $node): bool + { + if (!$node->default instanceof Node\Expr\ConstFetch) { + return false; + } + + return 'null' === $node->default->name->toLowerString(); + } } From 7e89311998f7dd864b27057f72673ec868091096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 09:41:40 +0100 Subject: [PATCH 49/93] Fix: Rename variable --- src/Methods/NoParameterWithNullDefaultValueRule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Methods/NoParameterWithNullDefaultValueRule.php b/src/Methods/NoParameterWithNullDefaultValueRule.php index 13c98ac0..02477a33 100644 --- a/src/Methods/NoParameterWithNullDefaultValueRule.php +++ b/src/Methods/NoParameterWithNullDefaultValueRule.php @@ -37,11 +37,11 @@ public function processNode( return []; } - $params = \array_filter($node->params, static function (Node\Param $node): bool { + $parametersWithNullDefaultValue = \array_filter($node->params, static function (Node\Param $node): bool { return self::hasNullDefaultValue($node); }); - if (0 === \count($params)) { + if (0 === \count($parametersWithNullDefaultValue)) { return []; } @@ -67,7 +67,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) ->build(); - }, $params)); + }, $parametersWithNullDefaultValue)); } $className = $classReflection->getName(); @@ -89,7 +89,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) ->build(); - }, $params)); + }, $parametersWithNullDefaultValue)); } private static function hasNullDefaultValue(Node\Param $node): bool From dbe1f4530078909fc8b06dab26660ce0cee7438a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 09:41:56 +0100 Subject: [PATCH 50/93] Fix: Rename parameter --- src/Methods/NoParameterWithNullDefaultValueRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Methods/NoParameterWithNullDefaultValueRule.php b/src/Methods/NoParameterWithNullDefaultValueRule.php index 02477a33..575a49e9 100644 --- a/src/Methods/NoParameterWithNullDefaultValueRule.php +++ b/src/Methods/NoParameterWithNullDefaultValueRule.php @@ -37,8 +37,8 @@ public function processNode( return []; } - $parametersWithNullDefaultValue = \array_filter($node->params, static function (Node\Param $node): bool { - return self::hasNullDefaultValue($node); + $parametersWithNullDefaultValue = \array_filter($node->params, static function (Node\Param $parameter): bool { + return self::hasNullDefaultValue($parameter); }); if (0 === \count($parametersWithNullDefaultValue)) { From 2758314ab6e85e1f51b7e91a357ffdd99f18089b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 09:42:28 +0100 Subject: [PATCH 51/93] Fix: Rename parameter --- src/Methods/NoParameterWithNullDefaultValueRule.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Methods/NoParameterWithNullDefaultValueRule.php b/src/Methods/NoParameterWithNullDefaultValueRule.php index 575a49e9..16deaa3d 100644 --- a/src/Methods/NoParameterWithNullDefaultValueRule.php +++ b/src/Methods/NoParameterWithNullDefaultValueRule.php @@ -51,9 +51,9 @@ public function processNode( $classReflection = $scope->getClassReflection(); if ($classReflection->isAnonymous()) { - return \array_values(\array_map(static function (Node\Param $node) use ($methodName): Rules\RuleError { + return \array_values(\array_map(static function (Node\Param $parameterWithNullDefaultValue) use ($methodName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ - $variable = $node->var; + $variable = $parameterWithNullDefaultValue->var; /** @var string $parameterName */ $parameterName = $variable->name; @@ -72,9 +72,9 @@ public function processNode( $className = $classReflection->getName(); - return \array_values(\array_map(static function (Node\Param $node) use ($className, $methodName): Rules\RuleError { + return \array_values(\array_map(static function (Node\Param $parameterWithNullDefaultValue) use ($className, $methodName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ - $variable = $node->var; + $variable = $parameterWithNullDefaultValue->var; /** @var string $parameterName */ $parameterName = $variable->name; From e38223880b0c55ccfdcacf591c00b33f919f9cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 09:42:44 +0100 Subject: [PATCH 52/93] Fix: Rename parameter --- src/Methods/NoParameterWithNullDefaultValueRule.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Methods/NoParameterWithNullDefaultValueRule.php b/src/Methods/NoParameterWithNullDefaultValueRule.php index 16deaa3d..778637ed 100644 --- a/src/Methods/NoParameterWithNullDefaultValueRule.php +++ b/src/Methods/NoParameterWithNullDefaultValueRule.php @@ -92,12 +92,12 @@ public function processNode( }, $parametersWithNullDefaultValue)); } - private static function hasNullDefaultValue(Node\Param $node): bool + private static function hasNullDefaultValue(Node\Param $parameter): bool { - if (!$node->default instanceof Node\Expr\ConstFetch) { + if (!$parameter->default instanceof Node\Expr\ConstFetch) { return false; } - return 'null' === $node->default->name->toLowerString(); + return 'null' === $parameter->default->name->toLowerString(); } } From 0f0e543a9744cfb741f3ce724ce62501010d7ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 09:43:25 +0100 Subject: [PATCH 53/93] Fix: Reset earlier --- src/Methods/NoParameterWithNullDefaultValueRule.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Methods/NoParameterWithNullDefaultValueRule.php b/src/Methods/NoParameterWithNullDefaultValueRule.php index 778637ed..7a09ec62 100644 --- a/src/Methods/NoParameterWithNullDefaultValueRule.php +++ b/src/Methods/NoParameterWithNullDefaultValueRule.php @@ -37,9 +37,9 @@ public function processNode( return []; } - $parametersWithNullDefaultValue = \array_filter($node->params, static function (Node\Param $parameter): bool { + $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { return self::hasNullDefaultValue($parameter); - }); + })); if (0 === \count($parametersWithNullDefaultValue)) { return []; @@ -51,7 +51,7 @@ public function processNode( $classReflection = $scope->getClassReflection(); if ($classReflection->isAnonymous()) { - return \array_values(\array_map(static function (Node\Param $parameterWithNullDefaultValue) use ($methodName): Rules\RuleError { + return \array_map(static function (Node\Param $parameterWithNullDefaultValue) use ($methodName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $parameterWithNullDefaultValue->var; @@ -67,12 +67,12 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) ->build(); - }, $parametersWithNullDefaultValue)); + }, $parametersWithNullDefaultValue); } $className = $classReflection->getName(); - return \array_values(\array_map(static function (Node\Param $parameterWithNullDefaultValue) use ($className, $methodName): Rules\RuleError { + return \array_map(static function (Node\Param $parameterWithNullDefaultValue) use ($className, $methodName): Rules\RuleError { /** @var Node\Expr\Variable $variable */ $variable = $parameterWithNullDefaultValue->var; @@ -89,7 +89,7 @@ public function processNode( return Rules\RuleErrorBuilder::message($message) ->identifier(ErrorIdentifier::noParameterWithNullDefaultValue()->toString()) ->build(); - }, $parametersWithNullDefaultValue)); + }, $parametersWithNullDefaultValue); } private static function hasNullDefaultValue(Node\Param $parameter): bool From 4c54a410406c630b28aa16d0d7b7632a20fc0002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 11:42:14 +0100 Subject: [PATCH 54/93] Fix: Namespace --- .../closure-with-parameter-with-nullable-type-declaration.php | 2 +- ...sure-with-parameter-with-nullable-union-type-declaration.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-type-declaration.php b/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-type-declaration.php index e2601687..5c6d3c38 100644 --- a/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-type-declaration.php +++ b/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-type-declaration.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Ergebnis\PHPStan\Rules\Test\Fixture\Closures\NoParameterWithNullDefaultValueRule\Success; +namespace Ergebnis\PHPStan\Rules\Test\Fixture\Closures\NoParameterWithNullDefaultValueRule\Failure; $foo = function (?string $bar) { return $bar; diff --git a/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-union-type-declaration.php b/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-union-type-declaration.php index c1d3540b..690b3121 100644 --- a/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-union-type-declaration.php +++ b/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-union-type-declaration.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Ergebnis\PHPStan\Rules\Test\Fixture\Closures\NoParameterWithNullDefaultValueRule\Success; +namespace Ergebnis\PHPStan\Rules\Test\Fixture\Closures\NoParameterWithNullDefaultValueRule\Failure; $foo = function (null|string $bar) { return $bar; From a65c12f3a2efb45a13657bc085d4a811bb57c1e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Fri, 13 Dec 2024 11:54:52 +0100 Subject: [PATCH 55/93] Fix: Rename methods --- src/Functions/NoNullableReturnTypeDeclarationRule.php | 4 ++-- src/Methods/NoNullableReturnTypeDeclarationRule.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Functions/NoNullableReturnTypeDeclarationRule.php b/src/Functions/NoNullableReturnTypeDeclarationRule.php index 86235ec5..e193279f 100644 --- a/src/Functions/NoNullableReturnTypeDeclarationRule.php +++ b/src/Functions/NoNullableReturnTypeDeclarationRule.php @@ -36,7 +36,7 @@ public function processNode( return []; } - if (!self::hasNullableReturnType($node)) { + if (!self::hasNullableReturnTypeDeclaration($node)) { return []; } @@ -52,7 +52,7 @@ public function processNode( ]; } - private static function hasNullableReturnType(Node\Stmt\Function_ $function): bool + private static function hasNullableReturnTypeDeclaration(Node\Stmt\Function_ $function): bool { $returnType = $function->getReturnType(); diff --git a/src/Methods/NoNullableReturnTypeDeclarationRule.php b/src/Methods/NoNullableReturnTypeDeclarationRule.php index 570254f7..e1d056ea 100644 --- a/src/Methods/NoNullableReturnTypeDeclarationRule.php +++ b/src/Methods/NoNullableReturnTypeDeclarationRule.php @@ -33,7 +33,7 @@ public function processNode( Node $node, Analyser\Scope $scope ): array { - if (!self::hasNullableReturnType($node)) { + if (!self::hasNullableReturnTypeDeclaration($node)) { return []; } @@ -66,7 +66,7 @@ public function processNode( ]; } - private static function hasNullableReturnType(Node\Stmt\ClassMethod $method): bool + private static function hasNullableReturnTypeDeclaration(Node\Stmt\ClassMethod $method): bool { $returnType = $method->getReturnType(); From 3e6f0426eae03dc21bff634ac51c67791478d309 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 09:13:36 +0000 Subject: [PATCH 56/93] github-actions(deps): Bump codecov/codecov-action from 5.1.1 to 5.1.2 Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.1.1 to 5.1.2. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v5.1.1...v5.1.2) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/integrate.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index f4142205..e3ec1855 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -65,7 +65,7 @@ jobs: 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.1.1" + uses: "codecov/codecov-action@v5.1.2" with: files: ".build/phpunit/logs/clover.xml" token: "${{ secrets.CODECOV_TOKEN }}" From 8e8cc49d780708e2bbe672dc009e7ef681cf7f48 Mon Sep 17 00:00:00 2001 From: ergebnis-bot Date: Wed, 1 Jan 2025 00:02:16 +0000 Subject: [PATCH 57/93] Enhancement: Update license year --- .php-cs-fixer.fixture.php | 2 +- .php-cs-fixer.php | 2 +- LICENSE.md | 2 +- src/Classes/FinalRule.php | 2 +- src/Classes/NoExtendsRule.php | 2 +- src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php | 2 +- src/Closures/NoNullableReturnTypeDeclarationRule.php | 2 +- src/Closures/NoParameterWithNullDefaultValueRule.php | 2 +- src/Closures/NoParameterWithNullableTypeDeclarationRule.php | 2 +- src/ErrorIdentifier.php | 2 +- src/Expressions/NoCompactRule.php | 2 +- src/Expressions/NoErrorSuppressionRule.php | 2 +- src/Expressions/NoEvalRule.php | 2 +- src/Expressions/NoIssetRule.php | 2 +- src/Files/DeclareStrictTypesRule.php | 2 +- src/Functions/NoNullableReturnTypeDeclarationRule.php | 2 +- src/Functions/NoParameterWithNullDefaultValueRule.php | 2 +- src/Functions/NoParameterWithNullableTypeDeclarationRule.php | 2 +- src/Methods/FinalInAbstractClassRule.php | 2 +- src/Methods/NoConstructorParameterWithDefaultValueRule.php | 2 +- src/Methods/NoNullableReturnTypeDeclarationRule.php | 2 +- src/Methods/NoParameterWithContainerTypeDeclarationRule.php | 2 +- src/Methods/NoParameterWithNullDefaultValueRule.php | 2 +- src/Methods/NoParameterWithNullableTypeDeclarationRule.php | 2 +- src/Methods/PrivateInFinalClassRule.php | 2 +- src/Statements/NoSwitchRule.php | 2 +- test/Integration/AbstractTestCase.php | 2 +- test/Integration/Classes/FinalRuleTest.php | 2 +- .../Classes/FinalRuleWithAbstractClassesAllowedTest.php | 2 +- test/Integration/Classes/FinalRuleWithAttributesTest.php | 2 +- .../Integration/Classes/FinalRuleWithExcludedClassNamesTest.php | 2 +- test/Integration/Classes/NoExtendsRuleTest.php | 2 +- .../Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php | 2 +- .../Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php | 2 +- .../Closures/NoNullableReturnTypeDeclarationRuleTest.php | 2 +- .../Closures/NoParameterWithNullDefaultValueRuleTest.php | 2 +- .../Closures/NoParameterWithNullableTypeDeclarationRuleTest.php | 2 +- test/Integration/Expressions/NoCompactRuleTest.php | 2 +- test/Integration/Expressions/NoErrorSuppressionRuleTest.php | 2 +- test/Integration/Expressions/NoEvalRuleTest.php | 2 +- test/Integration/Expressions/NoIssetRuleTest.php | 2 +- test/Integration/Files/DeclareStrictTypesRuleTest.php | 2 +- .../Functions/NoNullableReturnTypeDeclarationRuleTest.php | 2 +- .../Functions/NoParameterWithNullDefaultValueRuleTest.php | 2 +- .../NoParameterWithNullableTypeDeclarationRuleTest.php | 2 +- test/Integration/Methods/FinalInAbstractClassRuleTest.php | 2 +- .../Methods/NoConstructorParameterWithDefaultValueRuleTest.php | 2 +- .../Methods/NoNullableReturnTypeDeclarationRuleTest.php | 2 +- .../Methods/NoParameterWithContainerTypeDeclarationRuleTest.php | 2 +- .../Methods/NoParameterWithNullDefaultValueRuleTest.php | 2 +- .../Methods/NoParameterWithNullableTypeDeclarationRuleTest.php | 2 +- test/Integration/Methods/PrivateInFinalClassRuleTest.php | 2 +- test/Integration/Statements/NoSwitchRuleTest.php | 2 +- test/Unit/ErrorIdentifierTest.php | 2 +- 54 files changed, 54 insertions(+), 54 deletions(-) diff --git a/.php-cs-fixer.fixture.php b/.php-cs-fixer.fixture.php index 392a71ab..56bb6232 100644 --- a/.php-cs-fixer.fixture.php +++ b/.php-cs-fixer.fixture.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index ea14ad1a..3407c508 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/LICENSE.md b/LICENSE.md index afd82ebc..130e719a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # The MIT License (MIT) -Copyright (c) 2018-2024 Andreas Möller +Copyright (c) 2018-2025 Andreas Möller Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the _Software_), to deal in the Software without restriction, including without limitation the diff --git a/src/Classes/FinalRule.php b/src/Classes/FinalRule.php index 144155fb..63b1aec8 100644 --- a/src/Classes/FinalRule.php +++ b/src/Classes/FinalRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Classes/NoExtendsRule.php b/src/Classes/NoExtendsRule.php index beb050cf..93ecf7c6 100644 --- a/src/Classes/NoExtendsRule.php +++ b/src/Classes/NoExtendsRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php b/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php index 9882995d..6f1210df 100644 --- a/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php +++ b/src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Closures/NoNullableReturnTypeDeclarationRule.php b/src/Closures/NoNullableReturnTypeDeclarationRule.php index 87a188b3..28aef1db 100644 --- a/src/Closures/NoNullableReturnTypeDeclarationRule.php +++ b/src/Closures/NoNullableReturnTypeDeclarationRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Closures/NoParameterWithNullDefaultValueRule.php b/src/Closures/NoParameterWithNullDefaultValueRule.php index 144053b0..be414f70 100644 --- a/src/Closures/NoParameterWithNullDefaultValueRule.php +++ b/src/Closures/NoParameterWithNullDefaultValueRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php index 07acfbab..2a539da2 100644 --- a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/ErrorIdentifier.php b/src/ErrorIdentifier.php index 0c0adbe6..3559fb90 100644 --- a/src/ErrorIdentifier.php +++ b/src/ErrorIdentifier.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Expressions/NoCompactRule.php b/src/Expressions/NoCompactRule.php index f49bec8b..8e77d86c 100644 --- a/src/Expressions/NoCompactRule.php +++ b/src/Expressions/NoCompactRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Expressions/NoErrorSuppressionRule.php b/src/Expressions/NoErrorSuppressionRule.php index 642fba3f..49c0939c 100644 --- a/src/Expressions/NoErrorSuppressionRule.php +++ b/src/Expressions/NoErrorSuppressionRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Expressions/NoEvalRule.php b/src/Expressions/NoEvalRule.php index c3440533..b5420578 100644 --- a/src/Expressions/NoEvalRule.php +++ b/src/Expressions/NoEvalRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Expressions/NoIssetRule.php b/src/Expressions/NoIssetRule.php index ac2ce865..f1443d66 100644 --- a/src/Expressions/NoIssetRule.php +++ b/src/Expressions/NoIssetRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Files/DeclareStrictTypesRule.php b/src/Files/DeclareStrictTypesRule.php index 4d9ccc7e..5f9ec115 100644 --- a/src/Files/DeclareStrictTypesRule.php +++ b/src/Files/DeclareStrictTypesRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Functions/NoNullableReturnTypeDeclarationRule.php b/src/Functions/NoNullableReturnTypeDeclarationRule.php index e193279f..9346eea7 100644 --- a/src/Functions/NoNullableReturnTypeDeclarationRule.php +++ b/src/Functions/NoNullableReturnTypeDeclarationRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Functions/NoParameterWithNullDefaultValueRule.php b/src/Functions/NoParameterWithNullDefaultValueRule.php index 7cb5ee0e..3f8b3d47 100644 --- a/src/Functions/NoParameterWithNullDefaultValueRule.php +++ b/src/Functions/NoParameterWithNullDefaultValueRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php index c15e88d6..40a7025f 100644 --- a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Methods/FinalInAbstractClassRule.php b/src/Methods/FinalInAbstractClassRule.php index 75b2f812..89fc226f 100644 --- a/src/Methods/FinalInAbstractClassRule.php +++ b/src/Methods/FinalInAbstractClassRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Methods/NoConstructorParameterWithDefaultValueRule.php b/src/Methods/NoConstructorParameterWithDefaultValueRule.php index 233343e5..e8b7e34a 100644 --- a/src/Methods/NoConstructorParameterWithDefaultValueRule.php +++ b/src/Methods/NoConstructorParameterWithDefaultValueRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Methods/NoNullableReturnTypeDeclarationRule.php b/src/Methods/NoNullableReturnTypeDeclarationRule.php index e1d056ea..6a822670 100644 --- a/src/Methods/NoNullableReturnTypeDeclarationRule.php +++ b/src/Methods/NoNullableReturnTypeDeclarationRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php index a237b312..f64a8312 100644 --- a/src/Methods/NoParameterWithContainerTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithContainerTypeDeclarationRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Methods/NoParameterWithNullDefaultValueRule.php b/src/Methods/NoParameterWithNullDefaultValueRule.php index 7a09ec62..0e93f1e5 100644 --- a/src/Methods/NoParameterWithNullDefaultValueRule.php +++ b/src/Methods/NoParameterWithNullDefaultValueRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php index 9f260fde..e06fd0fb 100644 --- a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index 12576225..4c6ce4d7 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/src/Statements/NoSwitchRule.php b/src/Statements/NoSwitchRule.php index 4a52254e..127e5eed 100644 --- a/src/Statements/NoSwitchRule.php +++ b/src/Statements/NoSwitchRule.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/AbstractTestCase.php b/test/Integration/AbstractTestCase.php index 2f3f7456..f37660c0 100644 --- a/test/Integration/AbstractTestCase.php +++ b/test/Integration/AbstractTestCase.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Classes/FinalRuleTest.php b/test/Integration/Classes/FinalRuleTest.php index 075c4005..63ef1b72 100644 --- a/test/Integration/Classes/FinalRuleTest.php +++ b/test/Integration/Classes/FinalRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php b/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php index 7dcbb78b..f2cc5544 100644 --- a/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php +++ b/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Classes/FinalRuleWithAttributesTest.php b/test/Integration/Classes/FinalRuleWithAttributesTest.php index d414e7fa..abd42661 100644 --- a/test/Integration/Classes/FinalRuleWithAttributesTest.php +++ b/test/Integration/Classes/FinalRuleWithAttributesTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php b/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php index 3143f58d..189f9268 100644 --- a/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php +++ b/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Classes/NoExtendsRuleTest.php b/test/Integration/Classes/NoExtendsRuleTest.php index 2b9feec8..2b9a94de 100644 --- a/test/Integration/Classes/NoExtendsRuleTest.php +++ b/test/Integration/Classes/NoExtendsRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php b/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php index e6cd4be2..8e412e59 100644 --- a/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php +++ b/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php b/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php index 40baed59..66588982 100644 --- a/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php +++ b/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php index f6d70844..ae5837d2 100644 --- a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php index dc8c1e4d..2eb841a0 100644 --- a/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php index c944ac67..0432bf48 100644 --- a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Expressions/NoCompactRuleTest.php b/test/Integration/Expressions/NoCompactRuleTest.php index 08bd7abd..2b45ab2b 100644 --- a/test/Integration/Expressions/NoCompactRuleTest.php +++ b/test/Integration/Expressions/NoCompactRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Expressions/NoErrorSuppressionRuleTest.php b/test/Integration/Expressions/NoErrorSuppressionRuleTest.php index d1c734a7..6dbbf326 100644 --- a/test/Integration/Expressions/NoErrorSuppressionRuleTest.php +++ b/test/Integration/Expressions/NoErrorSuppressionRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Expressions/NoEvalRuleTest.php b/test/Integration/Expressions/NoEvalRuleTest.php index d4b962fd..70d0639c 100644 --- a/test/Integration/Expressions/NoEvalRuleTest.php +++ b/test/Integration/Expressions/NoEvalRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Expressions/NoIssetRuleTest.php b/test/Integration/Expressions/NoIssetRuleTest.php index 18912e10..24d420e3 100644 --- a/test/Integration/Expressions/NoIssetRuleTest.php +++ b/test/Integration/Expressions/NoIssetRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Files/DeclareStrictTypesRuleTest.php b/test/Integration/Files/DeclareStrictTypesRuleTest.php index 867350b1..92d6ffd8 100644 --- a/test/Integration/Files/DeclareStrictTypesRuleTest.php +++ b/test/Integration/Files/DeclareStrictTypesRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php index 5f31b856..64fc5017 100644 --- a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php index eb299243..84f2dc40 100644 --- a/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php index aa2d52bf..65d7c613 100644 --- a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Methods/FinalInAbstractClassRuleTest.php b/test/Integration/Methods/FinalInAbstractClassRuleTest.php index 4396e4a3..40525595 100644 --- a/test/Integration/Methods/FinalInAbstractClassRuleTest.php +++ b/test/Integration/Methods/FinalInAbstractClassRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php b/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php index 120ea798..59687e38 100644 --- a/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php +++ b/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php index b657ff58..29bf375c 100644 --- a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php b/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php index 2b289943..bfb4558f 100644 --- a/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php index 1cdb0c57..5ffc0c92 100644 --- a/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php index cd31b4fb..c488bb9b 100644 --- a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Methods/PrivateInFinalClassRuleTest.php b/test/Integration/Methods/PrivateInFinalClassRuleTest.php index b1b81ca8..ec0d4d40 100644 --- a/test/Integration/Methods/PrivateInFinalClassRuleTest.php +++ b/test/Integration/Methods/PrivateInFinalClassRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Integration/Statements/NoSwitchRuleTest.php b/test/Integration/Statements/NoSwitchRuleTest.php index 47119d26..24e62d77 100644 --- a/test/Integration/Statements/NoSwitchRuleTest.php +++ b/test/Integration/Statements/NoSwitchRuleTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. diff --git a/test/Unit/ErrorIdentifierTest.php b/test/Unit/ErrorIdentifierTest.php index 2055b6d2..4774d240 100644 --- a/test/Unit/ErrorIdentifierTest.php +++ b/test/Unit/ErrorIdentifierTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Copyright (c) 2018-2024 Andreas Möller + * Copyright (c) 2018-2025 Andreas Möller * * For the full copyright and license information, please view * the LICENSE.md file that was distributed with this source code. From c6fe553a8cdb0a46930deaff398c2a78646305e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 5 Jan 2025 16:06:29 +0100 Subject: [PATCH 58/93] Enhancement: Require phpstan/extension-installer --- composer.json | 4 +++- composer.lock | 54 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 25f091eb..e9e6e714 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "ergebnis/phpunit-slow-test-detector": "^2.17.0", "nette/di": "^3.1.10", "nikic/php-parser": "^4.19.4", + "phpstan/extension-installer": "^1.4.3", "phpstan/phpstan-deprecation-rules": "^1.2.1", "phpstan/phpstan-strict-rules": "^1.6.1", "phpunit/phpunit": "^9.6.21", @@ -52,7 +53,8 @@ "config": { "allow-plugins": { "ergebnis/composer-normalize": true, - "infection/extension-installer": true + "infection/extension-installer": true, + "phpstan/extension-installer": true }, "audit": { "abandoned": "report" diff --git a/composer.lock b/composer.lock index 2088f2f7..b28749e1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0632a3de04ffa3a44297212ff2984c46", + "content-hash": "a59576f025172422ac893480a8da1701", "packages": [ { "name": "phpstan/phpstan", @@ -3326,6 +3326,54 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "phpstan/extension-installer", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/85e90b3942d06b2326fba0403ec24fe912372936", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.0 || ^2.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.4.3" + }, + "time": "2024-09-04T20:21:43+00:00" + }, { "name": "phpstan/phpstan-deprecation-rules", "version": "1.2.1", @@ -7007,14 +7055,14 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", "ext-mbstring": "*" }, - "platform-dev": [], + "platform-dev": {}, "platform-overrides": { "php": "7.4.33" }, From 2910945005a103fc417aa39196fd46a9b8287fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 5 Jan 2025 16:48:02 +0100 Subject: [PATCH 59/93] Fix: Simplify --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 2fc59069..84c9fd5d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -10,7 +10,7 @@ parameters: - PHPStan\Testing\RuleTestCase excludePaths: - - %currentWorkingDirectory%/test/Fixture/ + - test/Fixture/ inferPrivatePropertyTypeFromConstructor: true From 3abc2b36ceef19fc63b963894f1eb3e79472d2da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 5 Jan 2025 23:09:30 +0100 Subject: [PATCH 60/93] Fix: Remove unnecessary attributes --- .../Success/ClassExtendingPhpUnitFrameworkTestCase.php | 1 - .../Success/ClassExtendingPhpUnitFrameworkTestCase.php | 1 - ...creteTestCaseExtendingAbstractTestCaseWithoutTestSuffix.php | 3 --- .../Failure/ConcreteTestCaseWithoutTestSuffix.php | 1 - .../Success/ConcreteTestCaseWithSuffixTest.php | 1 - .../Success/ImplicitlyAbstractTestCase.php | 1 - .../Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php | 2 +- 7 files changed, 1 insertion(+), 9 deletions(-) diff --git a/test/Fixture/Classes/NoExtendsRule/Success/ClassExtendingPhpUnitFrameworkTestCase.php b/test/Fixture/Classes/NoExtendsRule/Success/ClassExtendingPhpUnitFrameworkTestCase.php index 11425f06..e43df2d8 100644 --- a/test/Fixture/Classes/NoExtendsRule/Success/ClassExtendingPhpUnitFrameworkTestCase.php +++ b/test/Fixture/Classes/NoExtendsRule/Success/ClassExtendingPhpUnitFrameworkTestCase.php @@ -6,7 +6,6 @@ use PHPUnit\Framework; -#[Framework\Attributes\CoversNothing()] final class ClassExtendingPhpUnitFrameworkTestCase extends Framework\TestCase { } diff --git a/test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassExtendingPhpUnitFrameworkTestCase.php b/test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassExtendingPhpUnitFrameworkTestCase.php index 007efee4..1745ed26 100644 --- a/test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassExtendingPhpUnitFrameworkTestCase.php +++ b/test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassExtendingPhpUnitFrameworkTestCase.php @@ -6,7 +6,6 @@ use PHPUnit\Framework; -#[Framework\Attributes\CoversNothing()] final class ClassExtendingPhpUnitFrameworkTestCase extends Framework\TestCase { } diff --git a/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseExtendingAbstractTestCaseWithoutTestSuffix.php b/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseExtendingAbstractTestCaseWithoutTestSuffix.php index 28885f2d..2119f099 100644 --- a/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseExtendingAbstractTestCaseWithoutTestSuffix.php +++ b/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseExtendingAbstractTestCaseWithoutTestSuffix.php @@ -4,9 +4,6 @@ namespace Ergebnis\PHPStan\Rules\Test\Fixture\Classes\PHPUnit\Framework\TestCaseWithSuffixRule\Failure; -use PHPUnit\Framework; - -#[Framework\Attributes\CoversNothing()] final class ConcreteTestCaseExtendingAbstractTestCaseWithoutTestSuffix extends AbstractTestCase { } diff --git a/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseWithoutTestSuffix.php b/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseWithoutTestSuffix.php index 80f45b25..925e1bd7 100644 --- a/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseWithoutTestSuffix.php +++ b/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseWithoutTestSuffix.php @@ -6,7 +6,6 @@ use PHPUnit\Framework; -#[Framework\Attributes\CoversNothing()] final class ConcreteTestCaseWithoutTestSuffix extends Framework\TestCase { public function testFooIsNotBar(): void diff --git a/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ConcreteTestCaseWithSuffixTest.php b/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ConcreteTestCaseWithSuffixTest.php index 42a59399..38cdcebc 100644 --- a/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ConcreteTestCaseWithSuffixTest.php +++ b/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ConcreteTestCaseWithSuffixTest.php @@ -6,7 +6,6 @@ use PHPUnit\Framework; -#[Framework\Attributes\CoversNothing()] final class ConcreteTestCaseWithSuffixTest extends Framework\TestCase { public function testFooIsNotBar(): void diff --git a/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ImplicitlyAbstractTestCase.php b/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ImplicitlyAbstractTestCase.php index 13931359..4ad113f0 100644 --- a/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ImplicitlyAbstractTestCase.php +++ b/test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ImplicitlyAbstractTestCase.php @@ -6,7 +6,6 @@ use PHPUnit\Framework; -#[Framework\Attributes\CoversNothing] class ImplicitlyAbstractTestCase extends Framework\TestCase { abstract protected function foo(); diff --git a/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php b/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php index 66588982..5715df39 100644 --- a/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php +++ b/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php @@ -52,7 +52,7 @@ public static function provideCasesWhereAnalysisShouldFail(): iterable Test\Fixture\Classes\PHPUnit\Framework\TestCaseWithSuffixRule\Failure\ConcreteTestCaseExtendingAbstractTestCaseWithoutTestSuffix::class, Framework\TestCase::class, ), - 9, + 7, ], ], 'concrete-test-case-without-test-suffix' => [ From 84e071606b2901cdaa6dd8c5764f6a791061011f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 09:04:46 +0100 Subject: [PATCH 61/93] Fix: Keep using incorrect case in test case for NoCompactRule --- .php-cs-fixer.fixture.php | 1 + .../NoCompactRule/Failure/compact-used-with-incorrect-case.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.php-cs-fixer.fixture.php b/.php-cs-fixer.fixture.php index 56bb6232..fbc479d8 100644 --- a/.php-cs-fixer.fixture.php +++ b/.php-cs-fixer.fixture.php @@ -25,6 +25,7 @@ 'header_comment' => false, 'lowercase_keywords' => false, 'magic_method_casing' => false, + 'native_function_casing' => false, 'nullable_type_declaration' => false, 'protected_to_private' => false, 'static_lambda' => false, diff --git a/test/Fixture/Expressions/NoCompactRule/Failure/compact-used-with-incorrect-case.php b/test/Fixture/Expressions/NoCompactRule/Failure/compact-used-with-incorrect-case.php index 378d8545..65c28131 100644 --- a/test/Fixture/Expressions/NoCompactRule/Failure/compact-used-with-incorrect-case.php +++ b/test/Fixture/Expressions/NoCompactRule/Failure/compact-used-with-incorrect-case.php @@ -7,7 +7,7 @@ $foo = 9000; $bar = 42; -return \compact( +return \cOmPaCt( 'foo', 'bar', ); From 0756c2b7b2c2b2787dbc9a1007e37154e2982239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 09:11:50 +0100 Subject: [PATCH 62/93] Fix: Detect usages of compact() with incorrect case --- CHANGELOG.md | 1 + src/Expressions/NoCompactRule.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e500f1c..7caeeee6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ For a full diff see [`2.5.0...main`][2.5.0...main]. - Returned rule with error identifier ([#882]), by [@localheinz] - Adjusted `Methods\FinalInAbstractClassRule` to ignore Doctrine embeddables and entities ([#396]), by [@localheinz] +- Adjusted `Exprsssions\NoCompactRule` to detect usages of `compact()` with incorrect case ([#889]), by [@localheinz] ## [`2.5.0`][2.5.0] diff --git a/src/Expressions/NoCompactRule.php b/src/Expressions/NoCompactRule.php index 8e77d86c..cd12ffea 100644 --- a/src/Expressions/NoCompactRule.php +++ b/src/Expressions/NoCompactRule.php @@ -36,7 +36,7 @@ public function processNode( return []; } - if ('compact' !== $scope->resolveName($node->name)) { + if ('compact' !== \mb_strtolower($scope->resolveName($node->name))) { return []; } From 656ac4681b754ba4533a316e4591875fc65a7026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 09:55:27 +0100 Subject: [PATCH 63/93] Fix: Typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7caeeee6..ff07af7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ For a full diff see [`2.5.0...main`][2.5.0...main]. - Returned rule with error identifier ([#882]), by [@localheinz] - Adjusted `Methods\FinalInAbstractClassRule` to ignore Doctrine embeddables and entities ([#396]), by [@localheinz] -- Adjusted `Exprsssions\NoCompactRule` to detect usages of `compact()` with incorrect case ([#889]), by [@localheinz] +- Adjusted `Expressions\NoCompactRule` to detect usages of `compact()` with incorrect case ([#889]), by [@localheinz] ## [`2.5.0`][2.5.0] From 8b2a546e6bb01ecb5dbe21b8f6ecd44b9184f003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 09:57:34 +0100 Subject: [PATCH 64/93] Fix: Reference --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff07af7a..fc8557c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -551,6 +551,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [#878]: https://github.com/ergebnis/phpstan-rules/pull/878 [#880]: https://github.com/ergebnis/phpstan-rules/pull/880 [#882]: https://github.com/ergebnis/phpstan-rules/pull/882 +[#889]: https://github.com/ergebnis/phpstan-rules/pull/889 [@enumag]: https://github.com/enumag [@ergebnis]: https://github.com/ergebnis From bcdde2504bf1b5ea8c6dec9fa8cfadd6eeb64ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 09:53:27 +0100 Subject: [PATCH 65/93] Fix: Add test case for anonymous class --- test/Integration/Methods/PrivateInFinalClassRuleTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/Integration/Methods/PrivateInFinalClassRuleTest.php b/test/Integration/Methods/PrivateInFinalClassRuleTest.php index ec0d4d40..41436b14 100644 --- a/test/Integration/Methods/PrivateInFinalClassRuleTest.php +++ b/test/Integration/Methods/PrivateInFinalClassRuleTest.php @@ -47,6 +47,13 @@ public static function provideCasesWhereAnalysisShouldSucceed(): iterable public static function provideCasesWhereAnalysisShouldFail(): iterable { $paths = [ + 'anonymous-class-with-protected-method' => [ + __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Failure/AnonymousClassWithProtectedMethod.php', + [ + 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', + 8, + ], + ], 'final-class-with-protected-method' => [ __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Failure/FinalClassWithProtectedMethod.php', [ From 31024516e6305275fd1de3fce4b5089f37dd2067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 09:58:24 +0100 Subject: [PATCH 66/93] Fix: Use more appropriate message when detecting protected method in anonymous class --- CHANGELOG.md | 2 ++ src/Methods/PrivateInFinalClassRule.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc8557c8..b461c757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ For a full diff see [`2.5.0...main`][2.5.0...main]. - Returned rule with error identifier ([#882]), by [@localheinz] - Adjusted `Methods\FinalInAbstractClassRule` to ignore Doctrine embeddables and entities ([#396]), by [@localheinz] - Adjusted `Expressions\NoCompactRule` to detect usages of `compact()` with incorrect case ([#889]), by [@localheinz] +- Adjusted `Methods\PrivateInFinalClass` to use more appropriate message when detecting a `proected` method in an anonymous class ([#890]), by [@localheinz] ## [`2.5.0`][2.5.0] @@ -552,6 +553,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [#880]: https://github.com/ergebnis/phpstan-rules/pull/880 [#882]: https://github.com/ergebnis/phpstan-rules/pull/882 [#889]: https://github.com/ergebnis/phpstan-rules/pull/889 +[#890]: https://github.com/ergebnis/phpstan-rules/pull/890 [@enumag]: https://github.com/enumag [@ergebnis]: https://github.com/ergebnis diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index 4c6ce4d7..ec1f5062 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -60,6 +60,22 @@ public function processNode( } } + /** @var Reflection\ClassReflection $classReflection */ + $classReflection = $scope->getClassReflection(); + + if ($classReflection->isAnonymous()) { + $message = \sprintf( + 'Method %s() in anonymous class is protected, but since the containing class is final, it can be private.', + $node->name->name, + ); + + return [ + Rules\RuleErrorBuilder::message($message) + ->identifier(ErrorIdentifier::privateInFinalClass()->toString()) + ->build(), + ]; + } + $message = \sprintf( 'Method %s::%s() is protected, but since the containing class is final, it can be private.', $containingClass->getName(), From 911eef371adf927516add8a70fda3d3f8f2ef267 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 09:06:41 +0000 Subject: [PATCH 67/93] github-actions(deps): Bump shivammathur/setup-php from 2.31.1 to 2.32.0 Bumps [shivammathur/setup-php](https://github.com/shivammathur/setup-php) from 2.31.1 to 2.32.0. - [Release notes](https://github.com/shivammathur/setup-php/releases) - [Commits](https://github.com/shivammathur/setup-php/compare/2.31.1...2.32.0) --- updated-dependencies: - dependency-name: shivammathur/setup-php dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/integrate.yaml | 12 ++++++------ .github/workflows/renew.yaml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index e3ec1855..80a48e76 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -29,7 +29,7 @@ jobs: uses: "actions/checkout@v4.2.2" - name: "Set up PHP" - uses: "shivammathur/setup-php@2.31.1" + uses: "shivammathur/setup-php@2.32.0" with: coverage: "xdebug" extensions: "none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" @@ -97,7 +97,7 @@ jobs: strict: true - name: "Set up PHP" - uses: "shivammathur/setup-php@2.31.1" + uses: "shivammathur/setup-php@2.32.0" with: coverage: "none" extensions: "none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" @@ -162,7 +162,7 @@ jobs: uses: "actions/checkout@v4.2.2" - name: "Set up PHP" - uses: "shivammathur/setup-php@2.31.1" + uses: "shivammathur/setup-php@2.32.0" with: coverage: "none" extensions: "none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" @@ -218,7 +218,7 @@ jobs: uses: "actions/checkout@v4.2.2" - name: "Set up PHP" - uses: "shivammathur/setup-php@2.31.1" + uses: "shivammathur/setup-php@2.32.0" with: coverage: "none" extensions: "none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" @@ -268,7 +268,7 @@ jobs: uses: "actions/checkout@v4.2.2" - name: "Set up PHP" - uses: "shivammathur/setup-php@2.31.1" + uses: "shivammathur/setup-php@2.32.0" with: coverage: "none" extensions: "none, ctype, curl, dom, json, mbstring, opcache, pcntl, phar, posix, simplexml, tokenizer, xml, xmlwriter" @@ -326,7 +326,7 @@ jobs: uses: "actions/checkout@v4.2.2" - name: "Set up PHP" - uses: "shivammathur/setup-php@2.31.1" + uses: "shivammathur/setup-php@2.32.0" with: coverage: "none" extensions: "none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" diff --git a/.github/workflows/renew.yaml b/.github/workflows/renew.yaml index a6f08104..b13a7426 100644 --- a/.github/workflows/renew.yaml +++ b/.github/workflows/renew.yaml @@ -29,7 +29,7 @@ jobs: token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" - name: "Set up PHP" - uses: "shivammathur/setup-php@2.31.1" + uses: "shivammathur/setup-php@2.32.0" with: coverage: "none" extensions: "none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter" From b9e3cf93459170a19c3f7905ab8cef20b8f1a19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 5 Jan 2025 23:12:38 +0100 Subject: [PATCH 68/93] Fix: Remove abstract test case --- .php-cs-fixer.fixture.php | 22 +- composer.json | 1 + composer.lock | 2 +- .../Classes/FinalRule/AbstractClass.php | 9 + .../Classes/FinalRule/ExampleInterface.php | 9 + .../Classes/FinalRule/ExampleTrait.php | 9 + .../FinalRule/Failure/AbstractClass.php | 9 - test/Fixture/Classes/FinalRule/FinalClass.php | 9 + .../FinalClassWithAnonymousClass.php | 2 +- .../NeitherAbstractNorFinalClass.php | 2 +- ...inalClassWithAliasedOrmEntityAttribute.php | 2 +- ...ssWithEntityAnnotationInInlineDocBlock.php | 2 +- ...ithEntityAnnotationInMultilineDocBlock.php | 2 +- ...ithOrmEntityAnnotationInInlineDocBlock.php | 2 +- ...OrmEntityAnnotationInMultilineDocBlock.php | 2 +- ...appingEntityAnnotationInInlineDocBlock.php | 2 +- ...ingEntityAnnotationInMultilineDocBlock.php | 2 +- ...ifiedDoctrineOrmMappingEntityAttribute.php | 2 +- ...FinalClassWithQualifiedEntityAttribute.php | 2 +- ...assWithQualifiedMappingEntityAttribute.php | 2 +- ...WithQualifiedOrmMappingEntityAttribute.php | 2 +- ...ifiedDoctrineOrmMappingEntityAttribute.php | 2 +- ...nalClassWithUnqualifiedEntityAttribute.php | 2 +- ...ClassWithUnqualifiedOrmEntityAttribute.php | 2 +- ...thUnqualifiedOrmMappingEntityAttribute.php | 2 +- ...ithoutEntityAnnotationInInlineDocBlock.php | 2 +- ...outEntityAnnotationInMultilineDocBlock.php | 2 +- ...outOrmEntityAnnotationInInlineDocBlock.php | 2 +- ...OrmEntityAnnotationInMultilineDocBlock.php | 2 +- .../FinalRule/Success/ExampleInterface.php | 9 - .../FinalRule/Success/ExampleTrait.php | 9 - .../Classes/FinalRule/Success/FinalClass.php | 9 - .../{Success => }/TraitWithAnonymousClass.php | 2 +- .../anonymous-class.php => script.php} | 2 +- .../Failure/AbstractClass.php | 9 - .../Failure/NeitherAbstractNorFinalClass.php | 9 - .../Success/ExampleInterface.php | 9 - .../Success/ExampleTrait.php | 9 - .../Success/FinalClass.php | 9 - .../Success/FinalClassWithAnonymousClass.php | 18 -- .../Success/TraitWithAnonymousClass.php | 18 -- .../Success/anonymous-class.php | 12 - .../Failure/AbstractClass.php | 9 - .../Failure/NeitherAbstractNorFinalClass.php | 9 - .../Success/ExampleInterface.php | 9 - .../Success/ExampleTrait.php | 9 - .../Success/FinalClass.php | 9 - .../Success/FinalClassWithAnonymousClass.php | 18 -- ...herAbstractNorFinalClassButWhitelisted.php | 9 - .../Success/TraitWithAnonymousClass.php | 18 -- .../Success/anonymous-class.php | 12 - .../ClassExtendingOtherClass.php | 2 +- ...ClassExtendingPhpUnitFrameworkTestCase.php | 2 +- .../{Success => }/ExampleClass.php | 2 +- .../{Success => }/ExampleInterface.php | 2 +- .../anonymous-class-extending-other-class.php | 12 - .../InterfaceExtendingOtherInterface.php | 4 +- .../{Failure => }/OtherClass.php | 2 +- .../{Success => }/OtherInterface.php | 2 +- .../anonymous-class.php => script.php} | 9 +- .../Failure/ClassExtendingOtherClass.php | 9 - .../Failure/OtherClass.php | 9 - .../anonymous-class-extending-other-class.php | 12 - .../Success/ClassAllowedToBeExtended.php | 9 - ...ClassExtendingClassAllowedToBeExtended.php | 9 - ...ClassExtendingPhpUnitFrameworkTestCase.php | 11 - .../Success/ExampleClass.php | 9 - .../Success/ExampleInterface.php | 9 - .../InterfaceExtendingOtherInterface.php | 9 - .../Success/OtherInterface.php | 9 - ...extending-class-allowed-to-be-extended.php | 12 - .../Success/anonymous-class.php | 12 - .../{Failure => }/AbstractTestCase.php | 2 +- ...ExtendingAbstractTestCaseWithoutSuffix.php | 9 + .../ConcreteTestCaseWithSuffixTest.php | 2 +- ....php => ConcreteTestCaseWithoutSuffix.php} | 4 +- ...ndingAbstractTestCaseWithoutTestSuffix.php | 9 - .../ConcreteTestCaseWithoutTestSuffix.php | 15 - .../Success/ImplicitlyAbstractTestCase.php | 12 - ...-with-nullable-return-type-declaration.php | 9 - ...ble-union-type-return-type-declaration.php | 9 - .../closure-with-return-type-declaration.php | 9 - ...losure-without-return-type-declaration.php | 9 - .../script.php | 21 ++ ...with-parameter-with-null-default-value.php | 9 - ...amespace-referenced-null-default-value.php | 9 - ...wrongly-capitalized-null-default-value.php | 9 - ...-parameter-with-non-null-default-value.php | 9 - ...e-with-parameter-without-default-value.php | 9 - .../Success/closure-without-parameters.php | 8 - .../script.php | 28 ++ ...rameter-with-nullable-type-declaration.php | 9 - ...r-with-nullable-union-type-declaration.php | 9 - ...e-with-parameter-with-type-declaration.php | 9 - ...ith-parameter-without-type-declaration.php | 9 - .../Success/closure-without-parameters.php | 8 - .../script.php | 24 ++ .../Failure/compact-used-with-alias.php | 15 - .../compact-used-with-correct-case.php | 13 - .../compact-used-with-incorrect-case.php | 13 - .../compact-not-used.php => script.php} | 21 +- .../Success/error-suppression-not-used.php | 7 - .../error-suppression-used.php => script.php} | 4 +- .../Failure/eval-used-with-correct-case.php | 7 - .../Failure/eval-used-with-incorrect-case.php | 7 - .../{Success/eval-not-used.php => script.php} | 6 +- .../Failure/isset-used-with-correct-case.php | 9 - .../isset-used-with-incorrect-case.php | 9 - .../isset-not-used.php => script.php} | 10 +- .../{Success => }/file-empty.php | 0 ...re-strict-types-off-and-invalid-casing.php | 0 ...strict-types-off-and-multiple-declares.php | 0 ...h-comment-and-declare-strict-types-off.php | 0 ...are-strict-types-on-and-invalid-casing.php | 0 ...-strict-types-on-and-multiple-declares.php | 0 ...ict-types-on-and-namespace-declaration.php | 2 +- ...th-comment-and-declare-strict-types-on.php | 0 ...re-strict-types-off-and-invalid-casing.php | 0 ...strict-types-off-and-multiple-declares.php | 0 .../file-with-declare-strict-types-off.php | 0 ...are-strict-types-on-and-invalid-casing.php | 0 ...-strict-types-on-and-multiple-declares.php | 0 ...ict-types-on-and-namespace-declaration.php | 2 +- .../file-with-declare-strict-types-on.php | 0 .../{Failure => }/file-with-declare-ticks.php | 0 ...re-strict-types-off-and-invalid-casing.php | 0 ...strict-types-off-and-multiple-declares.php | 0 ...doc-block-and-declare-strict-types-off.php | 0 ...are-strict-types-on-and-invalid-casing.php | 0 ...-strict-types-on-and-multiple-declares.php | 0 ...ict-types-on-and-namespace-declaration.php | 2 +- ...-doc-block-and-declare-strict-types-on.php | 0 ...other-one-text-line-before-opening-tag.php | 0 ...h-shebang-and-declare-strict-types-off.php | 0 ...th-shebang-and-declare-strict-types-on.php | 0 .../file-with-text-before-opening-tag.php | 0 ...strict-types-and-namespace-declaration.php | 2 +- .../file-without-declare-strict-types.php | 0 ...-with-nullable-return-type-declaration.php | 10 - ...nullable-union-return-type-declaration.php | 10 - .../function-with-return-type-declaration.php | 10 - ...nction-without-return-type-declaration.php | 10 - .../script.php | 25 ++ ...with-parameter-with-null-default-value.php | 10 - ...amespace-referenced-null-default-value.php | 10 - ...wrongly-capitalized-null-default-value.php | 10 - ...-parameter-with-non-null-default-value.php | 10 - ...n-with-parameter-without-default-value.php | 10 - .../Success/function-without-parameters.php | 9 - .../script.php | 34 +++ ...rameter-with-nullable-type-declaration.php | 10 - ...r-with-nullable-union-type-declaration.php | 10 - ...n-with-parameter-with-type-declaration.php | 10 - ...ith-parameter-without-type-declaration.php | 10 - .../Success/function-without-parameters.php | 9 - .../script.php | 29 ++ .../AbstractClassWithAbstractMethod.php | 2 +- .../AbstractClassWithFinalProtectedMethod.php | 2 +- .../AbstractClassWithFinalPublicMethod.php | 2 +- .../AbstractClassWithNonFinalConstructor.php | 2 +- .../AbstractClassWithPrivateMethod.php | 2 +- .../AbstractClassWithProtectedMethod.php | 2 +- ...ndEmbeddableAnnotationInInlineDocBlock.php | 2 +- ...mbeddableAnnotationInMultilineDocBlock.php | 2 +- ...hProtectedMethodAndEmbeddableAttribute.php | 2 +- ...hodAndEntityAnnotationInInlineDocBlock.php | 2 +- ...AndEntityAnnotationInMultilineDocBlock.php | 2 +- ...sWithProtectedMethodAndEntityAttribute.php | 2 +- ...rmEmbeddableAnnotationInInlineDocBlock.php | 2 +- ...mbeddableAnnotationInMultilineDocBlock.php | 2 +- ...AndOrmEntityAnnotationInInlineDocBlock.php | 2 +- ...OrmEntityAnnotationInMultilineDocBlock.php | 2 +- ...ngEmbeddableAnnotationInInlineDocBlock.php | 2 +- ...mbeddableAnnotationInMultilineDocBlock.php | 2 +- ...appingEntityAnnotationInInlineDocBlock.php | 2 +- ...ingEntityAnnotationInMultilineDocBlock.php | 2 +- .../AbstractClassWithPublicMethod.php | 2 +- ...ndEmbeddableAnnotationInInlineDocBlock.php | 2 +- ...mbeddableAnnotationInMultilineDocBlock.php | 2 +- ...WithPublicMethodAndEmbeddableAttribute.php | 2 +- ...hodAndEntityAnnotationInInlineDocBlock.php | 2 +- ...AndEntityAnnotationInMultilineDocBlock.php | 2 +- ...lassWithPublicMethodAndEntityAttribute.php | 2 +- ...rmEmbeddableAnnotationInInlineDocBlock.php | 2 +- ...mbeddableAnnotationInMultilineDocBlock.php | 2 +- ...AndOrmEntityAnnotationInInlineDocBlock.php | 2 +- ...OrmEntityAnnotationInMultilineDocBlock.php | 2 +- ...ngEmbeddableAnnotationInInlineDocBlock.php | 2 +- ...mbeddableAnnotationInMultilineDocBlock.php | 2 +- ...appingEntityAnnotationInInlineDocBlock.php | 2 +- ...ingEntityAnnotationInMultilineDocBlock.php | 2 +- .../InterfaceWithPublicMethod.php | 2 +- ...orInClassWithParameterWithDefaultValue.php | 2 +- ...nClassWithParameterWithoutDefaultValue.php | 2 +- .../ConstructorInClassWithoutParameters.php | 2 +- ...orInTraitWithParameterWithDefaultValue.php | 2 +- ...nTraitWithParameterWithoutDefaultValue.php | 2 +- .../ConstructorInTraitWithoutParameters.php | 2 +- ...onInClassWithParameterWithDefaultValue.php | 2 +- ...lass-with-parameter-with-default-value.php | 11 - ...lass-with-parameter-with-default-value.php | 11 - ...odInClassWithParameterWithDefaultValue.php | 2 +- ...odInTraitWithParameterWithDefaultValue.php | 2 +- ...s-with-parameter-without-default-value.php | 11 - ...-in-anonymous-class-without-parameters.php | 11 - ...lass-with-parameter-with-default-value.php | 11 - .../script.php | 35 +++ ...ClassWithNullableReturnTypeDeclaration.php | 18 -- ...WithNullableUnionReturnTypeDeclaration.php | 18 -- ...ClassWithNullableReturnTypeDeclaration.php | 2 +- ...WithNullableUnionReturnTypeDeclaration.php | 2 +- ...MethodInClassWithReturnTypeDeclaration.php | 2 +- ...hodInClassWithoutReturnTypeDeclaration.php | 2 +- ...rfaceWithNullableReturnTypeDeclaration.php | 2 +- ...WithNullableUnionReturnTypeDeclaration.php | 2 +- ...odInInterfaceWithReturnTypeDeclaration.php | 2 +- ...nInterfaceWithoutReturnTypeDeclaration.php | 2 +- ...TraitWithNullableReturnTypeDeclaration.php | 2 +- ...MethodInTraitWithReturnTypeDeclaration.php | 2 +- ...hodInTraitWithoutReturnTypeDeclaration.php | 2 +- ...nonymousClassWithReturnTypeDeclaration.php | 18 -- ...ymousClassWithoutReturnTypeDeclaration.php | 18 -- .../script.php | 33 +++ .../ClassImplementingContainerInterface.php | 4 +- ...WithParameterWithSelfAsTypeDeclaration.php | 2 +- ...ingContainerInterfaceAsTypeDeclaration.php | 2 +- ...ceAsTypeDeclarationWhereNameIsExcluded.php | 4 +- ...ithContainerInterfaceAsTypeDeclaration.php | 2 +- ...ingContainerInterfaceAsTypeDeclaration.php | 2 +- ...dWithParameterWithOtherTypeDeclaration.php | 2 +- .../ClassWithMethodWithoutParameter.php | 2 +- .../{Success => }/ContainerInterface.php | 2 +- ...ontainer-interface-as-type-declaration.php | 12 - ...ontainer-interface-as-type-declaration.php | 14 - ...ontainer-interface-as-type-declaration.php | 12 - .../InterfaceExtendingContainerInterface.php | 2 +- ...ithContainerInterfaceAsTypeDeclaration.php | 2 +- ...ceAsTypeDeclarationWhereNameIsExcluded.php | 2 +- ...dWithParameterWithOtherTypeDeclaration.php | 2 +- .../InterfaceWithMethodWithoutParameter.php | 2 +- ...ype-declaration-where-name-is-excluded.php | 12 - ...-parameter-with-other-type-declaration.php | 11 - ...us-class-with-method-without-parameter.php | 11 - .../script.php | 46 +++ ...with-parameter-with-null-default-value.php | 12 - ...amespace-referenced-null-default-value.php | 12 - ...wrongly-capitalized-null-default-value.php | 12 - ...ssWithParameterWithNonNullDefaultValue.php | 2 +- ...ClassWithParameterWithNullDefaultValue.php | 2 +- ...ootNamespaceReferencedNullDefaultValue.php | 2 +- ...WithWronglyCapitalizedNullDefaultValue.php | 2 +- ...nClassWithParameterWithoutDefaultValue.php | 2 +- .../MethodInClassWithoutParameters.php | 2 +- ...ceWithParameterWithNonNullDefaultValue.php | 2 +- ...rfaceWithParameterWithNullDefaultValue.php | 2 +- ...ootNamespaceReferencedNullDefaultValue.php | 2 +- ...WithWronlgyCapitalizedNullDefaultValue.php | 2 +- ...erfaceWithParameterWithoutDefaultValue.php | 2 +- .../MethodInInterfaceWithoutParameters.php | 2 +- ...odInTraitWithParameterWithDefaultValue.php | 2 +- ...itWithParameterWithNonNullDefaultValue.php | 2 +- ...ootNamespaceReferencedNullDefaultValue.php | 2 +- ...WithWronlgyCapitalizedNullDefaultValue.php | 2 +- ...nTraitWithParameterWithoutDefaultValue.php | 2 +- .../MethodInTraitWithoutParameters.php | 2 +- ...-parameter-with-non-null-default-value.php | 12 - ...s-with-parameter-without-default-value.php | 12 - ...-in-anonymous-class-without-parameters.php | 11 - .../script.php | 46 +++ ...rameter-with-nullable-type-declaration.php | 12 - ...r-with-nullable-union-type-declaration.php | 12 - ...thParameterWithNullableTypeDeclaration.php | 2 +- ...ameterWithNullableUnionTypeDeclaration.php | 2 +- ...nClassWithParameterWithTypeDeclaration.php | 2 +- ...assWithParameterWithoutTypeDeclaration.php | 2 +- .../MethodInClassWithoutParameters.php | 2 +- ...thParameterWithNullableTypeDeclaration.php | 2 +- ...ameterWithNullableUnionTypeDeclaration.php | 2 +- ...erfaceWithParameterWithTypeDeclaration.php | 2 +- ...aceWithParameterWithoutTypeDeclaration.php | 2 +- .../MethodInInterfaceWithoutParameters.php | 2 +- ...thParameterWithNullableTypeDeclaration.php | 2 +- ...nTraitWithParameterWithTypeDeclaration.php | 2 +- ...aitWithParameterWithoutTypeDeclaration.php | 2 +- .../MethodInTraitWithoutParameters.php | 2 +- ...s-with-parameter-with-type-declaration.php | 12 - ...ith-parameter-without-type-declaration.php | 12 - ...-in-anonymous-class-without-parameters.php | 11 - .../script.php | 40 +++ ...endingAbstractClassWithProtectedMethod.php | 2 +- .../AbstractClassWithProtectedMethod.php | 2 +- .../ClassWithProtectedMethod.php | 2 +- .../FinalClassWithPrivateMethod.php | 2 +- .../FinalClassWithProtectedMethod.php | 2 +- ...sExtendingClassWithSameProtectedMethod.php | 2 +- ...dExtendingClassWithSameProtectedMethod.php | 2 +- ...FinalClassWithProtectedMethodFromTrait.php | 2 +- .../FinalClassWithPublicMethod.php | 2 +- .../TraitWithProtectedMethod.php | 2 +- ...lassWithProtectedMethod.php => script.php} | 4 +- .../Failure/switch-used-with-correct-case.php | 2 +- .../switch-used-with-incorrect-case.php | 2 +- .../NoSwitchRule/Success/switch-not-used.php | 2 +- test/Integration/AbstractTestCase.php | 67 ----- test/Integration/Classes/FinalRuleTest.php | 264 ++++++++++++++---- ...inalRuleWithAbstractClassesAllowedTest.php | 80 ------ .../Classes/FinalRuleWithAttributesTest.php | 108 ------- .../FinalRuleWithExcludedClassNamesTest.php | 92 ------ .../Integration/Classes/NoExtendsRuleTest.php | 70 +++-- ...RuleWithClassesAllowedToBeExtendedTest.php | 90 ------ .../Framework/TestCaseWithSuffixRuleTest.php | 48 +--- ...oNullableReturnTypeDeclarationRuleTest.php | 47 +--- ...oParameterWithNullDefaultValueRuleTest.php | 53 +--- ...terWithNullableTypeDeclarationRuleTest.php | 48 +--- .../Expressions/NoCompactRuleTest.php | 51 +--- .../NoErrorSuppressionRuleTest.php | 41 +-- .../Expressions/NoEvalRuleTest.php | 46 +-- .../Expressions/NoIssetRuleTest.php | 46 +-- .../Files/DeclareStrictTypesRuleTest.php | 94 +------ ...oNullableReturnTypeDeclarationRuleTest.php | 51 +--- ...oParameterWithNullDefaultValueRuleTest.php | 59 ++-- ...terWithNullableTypeDeclarationRuleTest.php | 52 +--- .../Methods/FinalInAbstractClassRuleTest.php | 79 +----- ...uctorParameterWithDefaultValueRuleTest.php | 79 ++---- ...oNullableReturnTypeDeclarationRuleTest.php | 87 ++---- ...erWithContainerTypeDeclarationRuleTest.php | 114 +++----- ...oParameterWithNullDefaultValueRuleTest.php | 114 ++------ ...terWithNullableTypeDeclarationRuleTest.php | 90 ++---- .../Methods/PrivateInFinalClassRuleTest.php | 61 ++-- .../Statements/NoSwitchRuleTest.php | 42 +-- test/Util/Helper.php | 35 +++ 331 files changed, 1206 insertions(+), 2787 deletions(-) create mode 100644 test/Fixture/Classes/FinalRule/AbstractClass.php create mode 100644 test/Fixture/Classes/FinalRule/ExampleInterface.php create mode 100644 test/Fixture/Classes/FinalRule/ExampleTrait.php delete mode 100644 test/Fixture/Classes/FinalRule/Failure/AbstractClass.php create mode 100644 test/Fixture/Classes/FinalRule/FinalClass.php rename test/Fixture/Classes/FinalRule/{Success => }/FinalClassWithAnonymousClass.php (78%) rename test/Fixture/Classes/FinalRule/{Failure => }/NeitherAbstractNorFinalClass.php (50%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Success => FinalRule}/NonFinalClassWithAliasedOrmEntityAttribute.php (61%) rename test/Fixture/Classes/FinalRule/{Success => }/NonFinalClassWithEntityAnnotationInInlineDocBlock.php (59%) rename test/Fixture/Classes/FinalRule/{Success => }/NonFinalClassWithEntityAnnotationInMultilineDocBlock.php (65%) rename test/Fixture/Classes/FinalRule/{Success => }/NonFinalClassWithOrmEntityAnnotationInInlineDocBlock.php (61%) rename test/Fixture/Classes/FinalRule/{Success => }/NonFinalClassWithOrmEntityAnnotationInMultilineDocBlock.php (67%) rename test/Fixture/Classes/FinalRule/{Success => }/NonFinalClassWithOrmMappingEntityAnnotationInInlineDocBlock.php (64%) rename test/Fixture/Classes/FinalRule/{Success => }/NonFinalClassWithOrmMappingEntityAnnotationInMultilineDocBlock.php (70%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Success => FinalRule}/NonFinalClassWithQualifiedDoctrineOrmMappingEntityAttribute.php (61%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Success => FinalRule}/NonFinalClassWithQualifiedEntityAttribute.php (60%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Success => FinalRule}/NonFinalClassWithQualifiedMappingEntityAttribute.php (61%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Success => FinalRule}/NonFinalClassWithQualifiedOrmMappingEntityAttribute.php (61%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Failure => FinalRule}/NonFinalClassWithUnqualifiedDoctrineOrmMappingEntityAttribute.php (61%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Failure => FinalRule}/NonFinalClassWithUnqualifiedEntityAttribute.php (53%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Failure => FinalRule}/NonFinalClassWithUnqualifiedOrmEntityAttribute.php (55%) rename test/Fixture/Classes/{FinalRuleWithAttributes/Failure => FinalRule}/NonFinalClassWithUnqualifiedOrmMappingEntityAttribute.php (58%) rename test/Fixture/Classes/FinalRule/{Failure => }/NonFinalClassWithoutEntityAnnotationInInlineDocBlock.php (60%) rename test/Fixture/Classes/FinalRule/{Failure => }/NonFinalClassWithoutEntityAnnotationInMultilineDocBlock.php (66%) rename test/Fixture/Classes/FinalRule/{Failure => }/NonFinalClassWithoutOrmEntityAnnotationInInlineDocBlock.php (61%) rename test/Fixture/Classes/FinalRule/{Failure => }/NonFinalClassWithoutOrmEntityAnnotationInMultilineDocBlock.php (67%) delete mode 100644 test/Fixture/Classes/FinalRule/Success/ExampleInterface.php delete mode 100644 test/Fixture/Classes/FinalRule/Success/ExampleTrait.php delete mode 100644 test/Fixture/Classes/FinalRule/Success/FinalClass.php rename test/Fixture/Classes/FinalRule/{Success => }/TraitWithAnonymousClass.php (77%) rename test/Fixture/Classes/FinalRule/{Success/anonymous-class.php => script.php} (64%) delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Failure/AbstractClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Failure/NeitherAbstractNorFinalClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/ExampleInterface.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/ExampleTrait.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/FinalClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/FinalClassWithAnonymousClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/TraitWithAnonymousClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/anonymous-class.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Failure/AbstractClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Failure/NeitherAbstractNorFinalClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/ExampleInterface.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/ExampleTrait.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/FinalClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/FinalClassWithAnonymousClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/NeitherAbstractNorFinalClassButWhitelisted.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/TraitWithAnonymousClass.php delete mode 100644 test/Fixture/Classes/FinalRuleWithExcludedClassNames/Success/anonymous-class.php rename test/Fixture/Classes/NoExtendsRule/{Failure => }/ClassExtendingOtherClass.php (92%) rename test/Fixture/Classes/NoExtendsRule/{Success => }/ClassExtendingPhpUnitFrameworkTestCase.php (94%) rename test/Fixture/Classes/NoExtendsRule/{Success => }/ExampleClass.php (90%) rename test/Fixture/Classes/NoExtendsRule/{Success => }/ExampleInterface.php (90%) delete mode 100644 test/Fixture/Classes/NoExtendsRule/Failure/anonymous-class-extending-other-class.php rename test/Fixture/Classes/NoExtendsRule/{Success => }/InterfaceExtendingOtherInterface.php (64%) rename test/Fixture/Classes/NoExtendsRule/{Failure => }/OtherClass.php (90%) rename test/Fixture/Classes/NoExtendsRule/{Success => }/OtherInterface.php (90%) rename test/Fixture/Classes/NoExtendsRule/{Success/anonymous-class.php => script.php} (58%) delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Failure/ClassExtendingOtherClass.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Failure/OtherClass.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Failure/anonymous-class-extending-other-class.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassAllowedToBeExtended.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassExtendingClassAllowedToBeExtended.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassExtendingPhpUnitFrameworkTestCase.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ExampleClass.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ExampleInterface.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/InterfaceExtendingOtherInterface.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/OtherInterface.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/anonymous-class-extending-class-allowed-to-be-extended.php delete mode 100644 test/Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/anonymous-class.php rename test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/{Failure => }/AbstractTestCase.php (82%) create mode 100644 test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/ConcreteTestCaseExtendingAbstractTestCaseWithoutSuffix.php rename test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/{Success => }/ConcreteTestCaseWithSuffixTest.php (88%) rename test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/{Success/ExplicitlyAbstractTestCase.php => ConcreteTestCaseWithoutSuffix.php} (55%) delete mode 100644 test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseExtendingAbstractTestCaseWithoutTestSuffix.php delete mode 100644 test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseWithoutTestSuffix.php delete mode 100644 test/Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ImplicitlyAbstractTestCase.php delete mode 100644 test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/Failure/closure-with-nullable-return-type-declaration.php delete mode 100644 test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/Failure/closure-with-nullable-union-type-return-type-declaration.php delete mode 100644 test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/Success/closure-with-return-type-declaration.php delete mode 100644 test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/Success/closure-without-return-type-declaration.php create mode 100644 test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/script.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/Failure/closure-with-parameter-with-null-default-value.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/Failure/closure-with-parameter-with-root-namespace-referenced-null-default-value.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/Failure/closure-with-parameter-with-wrongly-capitalized-null-default-value.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/Success/closure-with-parameter-with-non-null-default-value.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/Success/closure-with-parameter-without-default-value.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/Success/closure-without-parameters.php create mode 100644 test/Fixture/Closures/NoParameterWithNullDefaultValueRule/script.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-type-declaration.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-union-type-declaration.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Success/closure-with-parameter-with-type-declaration.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Success/closure-with-parameter-without-type-declaration.php delete mode 100644 test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Success/closure-without-parameters.php create mode 100644 test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/script.php delete mode 100644 test/Fixture/Expressions/NoCompactRule/Failure/compact-used-with-alias.php delete mode 100644 test/Fixture/Expressions/NoCompactRule/Failure/compact-used-with-correct-case.php delete mode 100644 test/Fixture/Expressions/NoCompactRule/Failure/compact-used-with-incorrect-case.php rename test/Fixture/Expressions/NoCompactRule/{Success/compact-not-used.php => script.php} (53%) delete mode 100644 test/Fixture/Expressions/NoErrorSuppressionRule/Success/error-suppression-not-used.php rename test/Fixture/Expressions/NoErrorSuppressionRule/{Failure/error-suppression-used.php => script.php} (75%) delete mode 100644 test/Fixture/Expressions/NoEvalRule/Failure/eval-used-with-correct-case.php delete mode 100644 test/Fixture/Expressions/NoEvalRule/Failure/eval-used-with-incorrect-case.php rename test/Fixture/Expressions/NoEvalRule/{Success/eval-not-used.php => script.php} (77%) delete mode 100644 test/Fixture/Expressions/NoIssetRule/Failure/isset-used-with-correct-case.php delete mode 100644 test/Fixture/Expressions/NoIssetRule/Failure/isset-used-with-incorrect-case.php rename test/Fixture/Expressions/NoIssetRule/{Success/isset-not-used.php => script.php} (67%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-empty.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-comment-and-declare-strict-types-off-and-invalid-casing.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-comment-and-declare-strict-types-off-and-multiple-declares.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-comment-and-declare-strict-types-off.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-comment-and-declare-strict-types-on-and-invalid-casing.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-comment-and-declare-strict-types-on-and-multiple-declares.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-comment-and-declare-strict-types-on-and-namespace-declaration.php (84%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-comment-and-declare-strict-types-on.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-declare-strict-types-off-and-invalid-casing.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-declare-strict-types-off-and-multiple-declares.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-declare-strict-types-off.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-declare-strict-types-on-and-invalid-casing.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-declare-strict-types-on-and-multiple-declares.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-declare-strict-types-on-and-namespace-declaration.php (83%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-declare-strict-types-on.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-declare-ticks.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-doc-block-and-declare-strict-types-off-and-invalid-casing.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-doc-block-and-declare-strict-types-off-and-multiple-declares.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-doc-block-and-declare-strict-types-off.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-doc-block-and-declare-strict-types-on-and-invalid-casing.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-doc-block-and-declare-strict-types-on-and-multiple-declares.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-doc-block-and-declare-strict-types-on-and-namespace-declaration.php (85%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-doc-block-and-declare-strict-types-on.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-shebang-and-another-one-text-line-before-opening-tag.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-shebang-and-declare-strict-types-off.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Success => }/file-with-shebang-and-declare-strict-types-on.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-with-text-before-opening-tag.php (100%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-without-declare-strict-types-and-namespace-declaration.php (79%) rename test/Fixture/Files/DeclareStrictTypesRule/{Failure => }/file-without-declare-strict-types.php (100%) delete mode 100644 test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/Failure/function-with-nullable-return-type-declaration.php delete mode 100644 test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/Failure/function-with-nullable-union-return-type-declaration.php delete mode 100644 test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/Success/function-with-return-type-declaration.php delete mode 100644 test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/Success/function-without-return-type-declaration.php create mode 100644 test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/script.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/Failure/function-with-parameter-with-null-default-value.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/Failure/function-with-parameter-with-root-namespace-referenced-null-default-value.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/Failure/function-with-parameter-with-wrongly-capitalized-null-default-value.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/Success/function-with-parameter-with-non-null-default-value.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/Success/function-with-parameter-without-default-value.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/Success/function-without-parameters.php create mode 100644 test/Fixture/Functions/NoParameterWithNullDefaultValueRule/script.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Failure/function-with-parameter-with-nullable-type-declaration.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Failure/function-with-parameter-with-nullable-union-type-declaration.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Success/function-with-parameter-with-type-declaration.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Success/function-with-parameter-without-type-declaration.php delete mode 100644 test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Success/function-without-parameters.php create mode 100644 test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/script.php rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithAbstractMethod.php (88%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithFinalProtectedMethod.php (89%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithFinalPublicMethod.php (89%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithNonFinalConstructor.php (89%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPrivateMethod.php (89%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Failure => }/AbstractClassWithProtectedMethod.php (89%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndEmbeddableAttribute.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndEntityAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndEntityAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndEntityAttribute.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmEmbeddableAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmEmbeddableAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmEntityAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmEntityAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmMappingEmbeddableAnnotationInInlineDocBlock.php (92%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmMappingEmbeddableAnnotationInMultilineDocBlock.php (92%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmMappingEntityAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithProtectedMethodAndOrmMappingEntityAnnotationInMultilineDocBlock.php (92%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Failure => }/AbstractClassWithPublicMethod.php (88%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndEmbeddableAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndEmbeddableAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndEmbeddableAttribute.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndEntityAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndEntityAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndEntityAttribute.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmEmbeddableAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmEmbeddableAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmEntityAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmEntityAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmMappingEmbeddableAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmMappingEmbeddableAnnotationInMultilineDocBlock.php (92%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmMappingEntityAnnotationInInlineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/AbstractClassWithPublicMethodAndOrmMappingEntityAnnotationInMultilineDocBlock.php (91%) rename test/Fixture/Methods/FinalInAbstractClassRule/{Success => }/InterfaceWithPublicMethod.php (87%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Failure => }/ConstructorInClassWithParameterWithDefaultValue.php (83%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/ConstructorInClassWithParameterWithoutDefaultValue.php (83%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/ConstructorInClassWithoutParameters.php (82%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/ConstructorInTraitWithParameterWithDefaultValue.php (83%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/ConstructorInTraitWithParameterWithoutDefaultValue.php (83%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/ConstructorInTraitWithoutParameters.php (81%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Failure => }/ConstructorWithWrongCapitalizationInClassWithParameterWithDefaultValue.php (85%) delete mode 100644 test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Failure/constructor-in-anonymous-class-with-parameter-with-default-value.php delete mode 100644 test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Failure/constructor-with-wrong-capitalization-in-anonymous-class-with-parameter-with-default-value.php rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/MethodInClassWithParameterWithDefaultValue.php (83%) rename test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/{Success => }/MethodInTraitWithParameterWithDefaultValue.php (83%) delete mode 100644 test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/constructor-in-anonymous-class-with-parameter-without-default-value.php delete mode 100644 test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/constructor-in-anonymous-class-without-parameters.php delete mode 100644 test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/method-in-anonymous-class-with-parameter-with-default-value.php create mode 100644 test/Fixture/Methods/NoConstructorParameterWithDefaultValueRule/script.php delete mode 100644 test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInAnonymousClassWithNullableReturnTypeDeclaration.php delete mode 100644 test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInAnonymousClassWithNullableUnionReturnTypeDeclaration.php rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Failure => }/MethodInClassWithNullableReturnTypeDeclaration.php (87%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Failure => }/MethodInClassWithNullableUnionReturnTypeDeclaration.php (87%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInClassWithReturnTypeDeclaration.php (86%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInClassWithoutReturnTypeDeclaration.php (86%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Failure => }/MethodInInterfaceWithNullableReturnTypeDeclaration.php (85%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Failure => }/MethodInInterfaceWithNullableUnionReturnTypeDeclaration.php (85%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInInterfaceWithReturnTypeDeclaration.php (84%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInInterfaceWithoutReturnTypeDeclaration.php (84%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInTraitWithNullableReturnTypeDeclaration.php (86%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInTraitWithReturnTypeDeclaration.php (86%) rename test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/{Success => }/MethodInTraitWithoutReturnTypeDeclaration.php (86%) delete mode 100644 test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInAnonymousClassWithReturnTypeDeclaration.php delete mode 100644 test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInAnonymousClassWithoutReturnTypeDeclaration.php create mode 100644 test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/script.php rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/ClassImplementingContainerInterface.php (77%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/ClassImplementingContainerInterfaceWithMethodWithParameterWithSelfAsTypeDeclaration.php (90%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/ClassWithMethodWithParameterWithClassImplementingContainerInterfaceAsTypeDeclaration.php (87%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/ClassWithMethodWithParameterWithClassImplementingContainerInterfaceAsTypeDeclarationWhereNameIsExcluded.php (63%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/ClassWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration.php (87%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/ClassWithMethodWithParameterWithInterfaceExtendingContainerInterfaceAsTypeDeclaration.php (87%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/ClassWithMethodWithParameterWithOtherTypeDeclaration.php (84%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/ClassWithMethodWithoutParameter.php (81%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/ContainerInterface.php (75%) delete mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/anonymous-class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration.php delete mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/anonymous-class-with-method-with-parameter-with-container-interface-as-type-declaration.php delete mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/anonymous-class-with-method-with-parameter-with-interface-extending-container-interface-as-type-declaration.php rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/InterfaceExtendingContainerInterface.php (82%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Failure => }/InterfaceWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration.php (86%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/InterfaceWithMethodWithParameterWithContainerInterfaceAsTypeDeclarationWhereNameIsExcluded.php (87%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/InterfaceWithMethodWithParameterWithOtherTypeDeclaration.php (84%) rename test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/{Success => }/InterfaceWithMethodWithoutParameter.php (81%) delete mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/anonymous-class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration-where-name-is-excluded.php delete mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/anonymous-class-with-method-with-parameter-with-other-type-declaration.php delete mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/anonymous-class-with-method-without-parameter.php create mode 100644 test/Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/script.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/method-in-anonymous-class-with-parameter-with-null-default-value.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/method-in-anonymous-class-with-parameter-with-root-namespace-referenced-null-default-value.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/method-in-anonymous-class-with-parameter-with-wrongly-capitalized-null-default-value.php rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInClassWithParameterWithNonNullDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Failure => }/MethodInClassWithParameterWithNullDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Failure => }/MethodInClassWithParameterWithRootNamespaceReferencedNullDefaultValue.php (87%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Failure => }/MethodInClassWithParameterWithWronglyCapitalizedNullDefaultValue.php (87%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInClassWithParameterWithoutDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInClassWithoutParameters.php (84%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInInterfaceWithParameterWithNonNullDefaultValue.php (85%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Failure => }/MethodInInterfaceWithParameterWithNullDefaultValue.php (85%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Failure => }/MethodInInterfaceWithParameterWithRootNamespaceReferencedNullDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Failure => }/MethodInInterfaceWithParameterWithWronlgyCapitalizedNullDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInInterfaceWithParameterWithoutDefaultValue.php (84%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInInterfaceWithoutParameters.php (83%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInTraitWithParameterWithDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInTraitWithParameterWithNonNullDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInTraitWithParameterWithRootNamespaceReferencedNullDefaultValue.php (87%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInTraitWithParameterWithWronlgyCapitalizedNullDefaultValue.php (87%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInTraitWithParameterWithoutDefaultValue.php (86%) rename test/Fixture/Methods/NoParameterWithNullDefaultValueRule/{Success => }/MethodInTraitWithoutParameters.php (83%) delete mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/method-in-anonymous-class-with-parameter-with-non-null-default-value.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/method-in-anonymous-class-with-parameter-without-default-value.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/method-in-anonymous-class-without-parameters.php create mode 100644 test/Fixture/Methods/NoParameterWithNullDefaultValueRule/script.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/method-in-anonymous-class-with-parameter-with-nullable-type-declaration.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/method-in-anonymous-class-with-parameter-with-nullable-union-type-declaration.php rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Failure => }/MethodInClassWithParameterWithNullableTypeDeclaration.php (85%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Failure => }/MethodInClassWithParameterWithNullableUnionTypeDeclaration.php (85%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInClassWithParameterWithTypeDeclaration.php (84%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInClassWithParameterWithoutTypeDeclaration.php (84%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInClassWithoutParameters.php (81%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Failure => }/MethodInInterfaceWithParameterWithNullableTypeDeclaration.php (83%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Failure => }/MethodInInterfaceWithParameterWithNullableUnionTypeDeclaration.php (83%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInInterfaceWithParameterWithTypeDeclaration.php (82%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInInterfaceWithParameterWithoutTypeDeclaration.php (82%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInInterfaceWithoutParameters.php (80%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInTraitWithParameterWithNullableTypeDeclaration.php (84%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInTraitWithParameterWithTypeDeclaration.php (84%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInTraitWithParameterWithoutTypeDeclaration.php (83%) rename test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/{Success => }/MethodInTraitWithoutParameters.php (81%) delete mode 100644 test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/method-in-anonymous-class-with-parameter-with-type-declaration.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/method-in-anonymous-class-with-parameter-without-type-declaration.php delete mode 100644 test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/method-in-anonymous-class-without-parameters.php create mode 100644 test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/script.php rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/AbstractClassExtendingAbstractClassWithProtectedMethod.php (90%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/AbstractClassWithProtectedMethod.php (89%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/ClassWithProtectedMethod.php (88%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/FinalClassWithPrivateMethod.php (89%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Failure => }/FinalClassWithProtectedMethod.php (89%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/FinalClassWithProtectedMethodExtendingClassExtendingClassWithSameProtectedMethod.php (93%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/FinalClassWithProtectedMethodExtendingClassWithSameProtectedMethod.php (92%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/FinalClassWithProtectedMethodFromTrait.php (89%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/FinalClassWithPublicMethod.php (89%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Success => }/TraitWithProtectedMethod.php (88%) rename test/Fixture/Methods/PrivateInFinalClassRule/{Failure/AnonymousClassWithProtectedMethod.php => script.php} (80%) delete mode 100644 test/Integration/AbstractTestCase.php delete mode 100644 test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php delete mode 100644 test/Integration/Classes/FinalRuleWithAttributesTest.php delete mode 100644 test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php delete mode 100644 test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php create mode 100644 test/Util/Helper.php diff --git a/.php-cs-fixer.fixture.php b/.php-cs-fixer.fixture.php index fbc479d8..debeb30e 100644 --- a/.php-cs-fixer.fixture.php +++ b/.php-cs-fixer.fixture.php @@ -26,6 +26,7 @@ 'lowercase_keywords' => false, 'magic_method_casing' => false, 'native_function_casing' => false, + 'native_function_invocation' => false, 'nullable_type_declaration' => false, 'protected_to_private' => false, 'static_lambda' => false, @@ -36,17 +37,16 @@ $config->getFinder() ->in(__DIR__ . '/test/Fixture/') ->notPath([ - 'Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ImplicitlyAbstractTestCase.php', - 'Closures/NoNullableReturnTypeDeclarationRule/Failure/closure-with-nullable-union-type-return-type-declaration.php', - 'Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-union-type-declaration.php', - 'Functions/NoNullableReturnTypeDeclarationRule/Failure/function-with-nullable-union-return-type-declaration.php', - 'Functions/NoParameterWithNullableTypeDeclarationRule/Failure/function-with-parameter-with-nullable-union-type-declaration.php', - 'Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInAnonymousClassWithNullableUnionReturnTypeDeclaration.php', - 'Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInClassWithNullableUnionReturnTypeDeclaration.php', - 'Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInInterfaceWithNullableUnionReturnTypeDeclaration.php', - 'Methods/NoParameterWithNullableTypeDeclarationRule/Failure/method-in-anonymous-class-with-parameter-with-nullable-union-type-declaration.php', - 'Methods/NoParameterWithNullableTypeDeclarationRule/Failure/MethodInClassWithParameterWithNullableUnionTypeDeclaration.php', - 'Methods/NoParameterWithNullableTypeDeclarationRule/Failure/MethodInInterfaceWithParameterWithNullableUnionTypeDeclaration.php', + 'Closures/NoNullableReturnTypeDeclarationRule/script.php', + 'Closures/NoParameterWithNullableTypeDeclarationRule/script.php', + 'Functions/NoNullableReturnTypeDeclarationRule/script.php', + 'Functions/NoParameterWithNullableTypeDeclarationRule/script.php', + 'Methods/NoNullableReturnTypeDeclarationRule/MethodInClassWithNullableUnionReturnTypeDeclaration.php', + 'Methods/NoNullableReturnTypeDeclarationRule/MethodInInterfaceWithNullableUnionReturnTypeDeclaration.php', + 'Methods/NoNullableReturnTypeDeclarationRule/script.php', + 'Methods/NoParameterWithNullableTypeDeclarationRule/MethodInClassWithParameterWithNullableUnionTypeDeclaration.php', + 'Methods/NoParameterWithNullableTypeDeclarationRule/MethodInInterfaceWithParameterWithNullableUnionTypeDeclaration.php', + 'Methods/NoParameterWithNullableTypeDeclarationRule/script.php', ]); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php_cs.fixture.cache'); diff --git a/composer.json b/composer.json index e9e6e714..40192616 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "phpstan/phpstan-strict-rules": "^1.6.1", "phpunit/phpunit": "^9.6.21", "psr/container": "^2.0.2", + "symfony/finder": "^5.4.45", "symfony/process": "^5.4.47" }, "autoload": { diff --git a/composer.lock b/composer.lock index b28749e1..38817c5c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a59576f025172422ac893480a8da1701", + "content-hash": "31f0e1fba4524e34ac08c37e71265e3c", "packages": [ { "name": "phpstan/phpstan", diff --git a/test/Fixture/Classes/FinalRule/AbstractClass.php b/test/Fixture/Classes/FinalRule/AbstractClass.php new file mode 100644 index 00000000..fa9f7101 --- /dev/null +++ b/test/Fixture/Classes/FinalRule/AbstractClass.php @@ -0,0 +1,9 @@ + - */ -abstract class AbstractTestCase extends Testing\RuleTestCase -{ - /** - * @dataProvider provideCasesWhereAnalysisShouldSucceed - */ - final public function testAnalysisSucceeds(string $path): void - { - self::assertFileExists($path); - - $this->analyse( - [ - $path, - ], - [], - ); - } - - /** - * @dataProvider provideCasesWhereAnalysisShouldFail - * - * @param array{0: string, 1: int} $error - */ - final public function testAnalysisFails(string $path, array $error): void - { - self::assertFileExists($path); - - $this->analyse( - [ - $path, - ], - [ - $error, - ], - ); - } - - /** - * @return iterable - */ - abstract public static function provideCasesWhereAnalysisShouldSucceed(): iterable; - - /** - * @return iterable - */ - abstract public static function provideCasesWhereAnalysisShouldFail(): iterable; -} diff --git a/test/Integration/Classes/FinalRuleTest.php b/test/Integration/Classes/FinalRuleTest.php index 63ef1b72..542ffc41 100644 --- a/test/Integration/Classes/FinalRuleTest.php +++ b/test/Integration/Classes/FinalRuleTest.php @@ -15,121 +15,265 @@ use Ergebnis\PHPStan\Rules\Classes; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Classes\FinalRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class FinalRuleTest extends Test\Integration\AbstractTestCase +final class FinalRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'final-class' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/FinalClass.php', - 'final-class-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/FinalClassWithAnonymousClass.php', - 'interface' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/ExampleInterface.php', - 'non-final-class-with-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/NonFinalClassWithEntityAnnotationInInlineDocBlock.php', - 'non-final-class-with-entity-annotation-in-multi-line-doc-block' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/NonFinalClassWithEntityAnnotationInMultilineDocBlock.php', - 'non-final-class-with-orm-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/NonFinalClassWithOrmEntityAnnotationInInlineDocBlock.php', - 'non-final-class-with-orm-entity-annotation-in-multi-line-doc-block' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/NonFinalClassWithOrmEntityAnnotationInMultilineDocBlock.php', - 'non-final-class-with-orm-mapping-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/NonFinalClassWithOrmMappingEntityAnnotationInInlineDocBlock.php', - 'non-final-class-with-orm-mapping-entity-annotation-in-multi-line-doc-block' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/NonFinalClassWithOrmMappingEntityAnnotationInMultilineDocBlock.php', - 'script-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/anonymous-class.php', - 'trait' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/ExampleTrait.php', - 'trait-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRule/Success/TraitWithAnonymousClass.php', - ]; + use Test\Util\Helper; + private bool $allowAbstractClasses; - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + /** + * @var list + */ + private array $classesNotRequiredToBeAbstractOrFinal; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testFinalRule(): void { - $paths = [ - 'abstract-class' => [ - __DIR__ . '/../../Fixture/Classes/FinalRule/Failure/AbstractClass.php', + $this->allowAbstractClasses = false; + $this->classesNotRequiredToBeAbstractOrFinal = []; + + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Classes/FinalRule'), + [ [ \sprintf( 'Class %s is not final.', - Test\Fixture\Classes\FinalRule\Failure\AbstractClass::class, + Test\Fixture\Classes\FinalRule\AbstractClass::class, ), 7, ], - ], - 'neither-abstract-nor-final-class' => [ - __DIR__ . '/../../Fixture/Classes/FinalRule/Failure/NeitherAbstractNorFinalClass.php', [ \sprintf( 'Class %s is not final.', - Test\Fixture\Classes\FinalRule\Failure\NeitherAbstractNorFinalClass::class, + Test\Fixture\Classes\FinalRule\NeitherAbstractNorFinalClass::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedDoctrineOrmMappingEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedOrmEntityAttribute::class, ), 7, ], - ], - 'non-final-class-without-entity-annotation-in-inline-doc-block' => [ - __DIR__ . '/../../Fixture/Classes/FinalRule/Failure/NonFinalClassWithoutEntityAnnotationInInlineDocBlock.php', [ \sprintf( 'Class %s is not final.', - Test\Fixture\Classes\FinalRule\Failure\NonFinalClassWithoutEntityAnnotationInInlineDocBlock::class, + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedOrmMappingEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutEntityAnnotationInInlineDocBlock::class, ), 8, ], - ], - 'non-final-class-without-entity-annotation-in-multi-line-doc-block' => [ - __DIR__ . '/../../Fixture/Classes/FinalRule/Failure/NonFinalClassWithoutEntityAnnotationInMultilineDocBlock.php', [ \sprintf( 'Class %s is not final.', - Test\Fixture\Classes\FinalRule\Failure\NonFinalClassWithoutEntityAnnotationInMultilineDocBlock::class, + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutEntityAnnotationInMultilineDocBlock::class, ), 12, ], - ], - 'non-final-class-without-orm-entity-annotation-in-inline-doc-block' => [ - __DIR__ . '/../../Fixture/Classes/FinalRule/Failure/NonFinalClassWithoutOrmEntityAnnotationInInlineDocBlock.php', [ \sprintf( 'Class %s is not final.', - Test\Fixture\Classes\FinalRule\Failure\NonFinalClassWithoutOrmEntityAnnotationInInlineDocBlock::class, + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutOrmEntityAnnotationInInlineDocBlock::class, ), 8, ], - ], - 'non-final-class-without-orm-entity-annotation-in-multi-line-doc-block' => [ - __DIR__ . '/../../Fixture/Classes/FinalRule/Failure/NonFinalClassWithoutOrmEntityAnnotationInMultilineDocBlock.php', [ \sprintf( 'Class %s is not final.', - Test\Fixture\Classes\FinalRule\Failure\NonFinalClassWithoutOrmEntityAnnotationInMultilineDocBlock::class, + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutOrmEntityAnnotationInMultilineDocBlock::class, ), 12, ], ], + ); + } + + public function testFinalRuleWithAllowAbstractClasses(): void + { + $this->allowAbstractClasses = true; + $this->classesNotRequiredToBeAbstractOrFinal = []; + + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Classes/FinalRule'), + [ + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NeitherAbstractNorFinalClass::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedDoctrineOrmMappingEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedOrmEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedOrmMappingEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutEntityAnnotationInInlineDocBlock::class, + ), + 8, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutEntityAnnotationInMultilineDocBlock::class, + ), + 12, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutOrmEntityAnnotationInInlineDocBlock::class, + ), + 8, + ], + [ + \sprintf( + 'Class %s is neither abstract nor final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutOrmEntityAnnotationInMultilineDocBlock::class, + ), + 12, + ], + ], + ); + } + + public function testFinalRuleWithClassesNotRequiredToBeAbstractOrFinal(): void + { + $this->allowAbstractClasses = false; + $this->classesNotRequiredToBeAbstractOrFinal = [ + Test\Fixture\Classes\FinalRule\NeitherAbstractNorFinalClass::class, ]; - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Classes/FinalRule'), + [ + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\AbstractClass::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedDoctrineOrmMappingEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedOrmEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithUnqualifiedOrmMappingEntityAttribute::class, + ), + 7, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutEntityAnnotationInInlineDocBlock::class, + ), + 8, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutEntityAnnotationInMultilineDocBlock::class, + ), + 12, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutOrmEntityAnnotationInInlineDocBlock::class, + ), + 8, + ], + [ + \sprintf( + 'Class %s is not final.', + Test\Fixture\Classes\FinalRule\NonFinalClassWithoutOrmEntityAnnotationInMultilineDocBlock::class, + ), + 12, + ], + ], + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Classes\FinalRule( - false, - [], + $this->allowAbstractClasses, + $this->classesNotRequiredToBeAbstractOrFinal, ); } } diff --git a/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php b/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php deleted file mode 100644 index f2cc5544..00000000 --- a/test/Integration/Classes/FinalRuleWithAbstractClassesAllowedTest.php +++ /dev/null @@ -1,80 +0,0 @@ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Failure/AbstractClass.php', - 'final-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/FinalClass.php', - 'final-class-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/FinalClassWithAnonymousClass.php', - 'interface' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/ExampleInterface.php', - 'script-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/anonymous-class.php', - 'trait' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/ExampleTrait.php', - 'trait-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Success/TraitWithAnonymousClass.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable - { - $paths = [ - 'neither-abstract-nor-final-class' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAbstractClassesAllowed/Failure/NeitherAbstractNorFinalClass.php', - [ - \sprintf( - 'Class %s is neither abstract nor final.', - Test\Fixture\Classes\FinalRuleWithAbstractClassesAllowed\Failure\NeitherAbstractNorFinalClass::class, - ), - 7, - ], - ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } - } - - /** - * @return Rules\Rule - */ - protected function getRule(): Rules\Rule - { - return new Classes\FinalRule( - true, - [], - ); - } -} diff --git a/test/Integration/Classes/FinalRuleWithAttributesTest.php b/test/Integration/Classes/FinalRuleWithAttributesTest.php deleted file mode 100644 index abd42661..00000000 --- a/test/Integration/Classes/FinalRuleWithAttributesTest.php +++ /dev/null @@ -1,108 +0,0 @@ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Success/NonFinalClassWithAliasedOrmEntityAttribute.php', - 'non-final-class-with-qualified-doctrine-orm-mapping-entity-attribute' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Success/NonFinalClassWithQualifiedDoctrineOrmMappingEntityAttribute.php', - 'non-final-class-with-qualified-entity-attribute' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Success/NonFinalClassWithQualifiedEntityAttribute.php', - 'non-final-class-with-qualified-mapping-entity-attribute' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Success/NonFinalClassWithQualifiedMappingEntityAttribute.php', - 'non-final-class-with-qualified-orm-mapping-entity-attribute' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Success/NonFinalClassWithQualifiedOrmMappingEntityAttribute.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable - { - $paths = [ - 'non-final-class-with-unqualified-doctrine-orm-mapping-entity-attribute' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Failure/NonFinalClassWithUnqualifiedDoctrineOrmMappingEntityAttribute.php', - [ - \sprintf( - 'Class %s is not final.', - Test\Fixture\Classes\FinalRuleWithAttributes\Failure\NonFinalClassWithUnqualifiedDoctrineOrmMappingEntityAttribute::class, - ), - 7, - ], - ], - 'non-final-class-with-unqualified-entity-attribute' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Failure/NonFinalClassWithUnqualifiedEntityAttribute.php', - [ - \sprintf( - 'Class %s is not final.', - Test\Fixture\Classes\FinalRuleWithAttributes\Failure\NonFinalClassWithUnqualifiedEntityAttribute::class, - ), - 7, - ], - ], - 'non-final-class-with-unqualified-orm-entity-attribute' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Failure/NonFinalClassWithUnqualifiedOrmEntityAttribute.php', - [ - \sprintf( - 'Class %s is not final.', - Test\Fixture\Classes\FinalRuleWithAttributes\Failure\NonFinalClassWithUnqualifiedOrmEntityAttribute::class, - ), - 7, - ], - ], - 'non-final-class-with-unqualified-orm-mapping-entity-attribute' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithAttributes/Failure/NonFinalClassWithUnqualifiedOrmMappingEntityAttribute.php', - [ - \sprintf( - 'Class %s is not final.', - Test\Fixture\Classes\FinalRuleWithAttributes\Failure\NonFinalClassWithUnqualifiedOrmMappingEntityAttribute::class, - ), - 7, - ], - ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } - } - - /** - * @return Rules\Rule - */ - protected function getRule(): Rules\Rule - { - return new Classes\FinalRule( - false, - [], - ); - } -} diff --git a/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php b/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php deleted file mode 100644 index 189f9268..00000000 --- a/test/Integration/Classes/FinalRuleWithExcludedClassNamesTest.php +++ /dev/null @@ -1,92 +0,0 @@ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/NeitherAbstractNorFinalClassButWhitelisted.php', - 'final-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/FinalClass.php', - 'final-class-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/FinalClassWithAnonymousClass.php', - 'interface' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/ExampleInterface.php', - 'script-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/anonymous-class.php', - 'trait' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/ExampleTrait.php', - 'trait-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Success/TraitWithAnonymousClass.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable - { - $paths = [ - 'abstract-class' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Failure/AbstractClass.php', - [ - \sprintf( - 'Class %s is not final.', - Test\Fixture\Classes\FinalRuleWithExcludedClassNames\Failure\AbstractClass::class, - ), - 7, - ], - ], - 'neither-abstract-nor-final-class' => [ - __DIR__ . '/../../Fixture/Classes/FinalRuleWithExcludedClassNames/Failure/NeitherAbstractNorFinalClass.php', - [ - \sprintf( - 'Class %s is not final.', - Test\Fixture\Classes\FinalRuleWithExcludedClassNames\Failure\NeitherAbstractNorFinalClass::class, - ), - 7, - ], - ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } - } - - /** - * @return Rules\Rule - */ - protected function getRule(): Rules\Rule - { - return new Classes\FinalRule( - false, - [ - Test\Fixture\Classes\FinalRuleWithExcludedClassNames\Success\NeitherAbstractNorFinalClassButWhitelisted::class, - ], - ); - } -} diff --git a/test/Integration/Classes/NoExtendsRuleTest.php b/test/Integration/Classes/NoExtendsRuleTest.php index 2b9a94de..9667bb40 100644 --- a/test/Integration/Classes/NoExtendsRuleTest.php +++ b/test/Integration/Classes/NoExtendsRuleTest.php @@ -15,72 +15,66 @@ use Ergebnis\PHPStan\Rules\Classes; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Classes\NoExtendsRule * + * @extends Testing\RuleTestCase + * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier */ -final class NoExtendsRuleTest extends Test\Integration\AbstractTestCase +final class NoExtendsRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'class' => __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Success/ExampleClass.php', - 'class-extending-php-unit-framework-test-case' => __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Success/ClassExtendingPhpUnitFrameworkTestCase.php', - 'interface' => __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Success/ExampleInterface.php', - 'interface-extending-other-interface' => __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Success/InterfaceExtendingOtherInterface.php', - 'script-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Success/anonymous-class.php', - ]; + use Test\Util\Helper; - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + /** + * @var list + */ + private array $classesAllowedToBeExtended; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoExtendsRule(): void { - $paths = [ - 'class-extending-other-class' => [ - __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Failure/ClassExtendingOtherClass.php', + $this->classesAllowedToBeExtended = []; + + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Classes/NoExtendsRule'), + [ [ \sprintf( 'Class "%s" is not allowed to extend "%s".', - Test\Fixture\Classes\NoExtendsRule\Failure\ClassExtendingOtherClass::class, - Test\Fixture\Classes\NoExtendsRule\Failure\OtherClass::class, + Test\Fixture\Classes\NoExtendsRule\ClassExtendingOtherClass::class, + Test\Fixture\Classes\NoExtendsRule\OtherClass::class, ), 7, ], - ], - 'script-with-anonymous-class-extending-other-class' => [ - __DIR__ . '/../../Fixture/Classes/NoExtendsRule/Failure/anonymous-class-extending-other-class.php', [ \sprintf( 'Anonymous class is not allowed to extend "%s".', - Test\Fixture\Classes\NoExtendsRule\Failure\OtherClass::class, + Test\Fixture\Classes\NoExtendsRule\OtherClass::class, ), - 7, + 10, ], ], + ); + } + + public function testNoExtendsRuleWithClassesAllowedToBeExtended(): void + { + $this->classesAllowedToBeExtended = [ + Test\Fixture\Classes\NoExtendsRule\OtherClass::class, ]; - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Classes/NoExtendsRule'), + [ + ], + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { - return new Classes\NoExtendsRule([]); + return new Classes\NoExtendsRule($this->classesAllowedToBeExtended); } } diff --git a/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php b/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php deleted file mode 100644 index 8e412e59..00000000 --- a/test/Integration/Classes/NoExtendsRuleWithClassesAllowedToBeExtendedTest.php +++ /dev/null @@ -1,90 +0,0 @@ - __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ExampleClass.php', - 'class-extending-class-allowed-to-be-extended' => __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassExtendingClassAllowedToBeExtended.php', - 'class-extending-php-unit-framework-test-case' => __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ClassExtendingPhpUnitFrameworkTestCase.php', - 'interface' => __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/ExampleInterface.php', - 'interface-extending-other-interface' => __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/InterfaceExtendingOtherInterface.php', - 'script-with-anonymous-class' => __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/anonymous-class.php', - 'script-with-anonymous-class-extending-class-allowed-to-be-extended' => __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Success/anonymous-class-extending-class-allowed-to-be-extended.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable - { - $paths = [ - 'class-extending-other-class' => [ - __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Failure/ClassExtendingOtherClass.php', - [ - \sprintf( - 'Class "%s" is not allowed to extend "%s".', - Test\Fixture\Classes\NoExtendsRuleWithClassesAllowedToBeExtended\Failure\ClassExtendingOtherClass::class, - Test\Fixture\Classes\NoExtendsRuleWithClassesAllowedToBeExtended\Failure\OtherClass::class, - ), - 7, - ], - ], - 'script-with-anonymous-class-extending-other-class' => [ - __DIR__ . '/../../Fixture/Classes/NoExtendsRuleWithClassesAllowedToBeExtended/Failure/anonymous-class-extending-other-class.php', - [ - \sprintf( - 'Anonymous class is not allowed to extend "%s".', - Test\Fixture\Classes\NoExtendsRuleWithClassesAllowedToBeExtended\Failure\OtherClass::class, - ), - 7, - ], - ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } - } - - /** - * @return Rules\Rule - */ - protected function getRule(): Rules\Rule - { - return new Classes\NoExtendsRule([ - Test\Fixture\Classes\NoExtendsRuleWithClassesAllowedToBeExtended\Success\ClassAllowedToBeExtended::class, - ]); - } -} diff --git a/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php b/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php index 5715df39..206ebf87 100644 --- a/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php +++ b/test/Integration/Classes/PHPUnit/Framework/TestCaseWithSuffixRuleTest.php @@ -15,70 +15,46 @@ use Ergebnis\PHPStan\Rules\Classes; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; use PHPUnit\Framework; /** * @covers \Ergebnis\PHPStan\Rules\Classes\PHPUnit\Framework\TestCaseWithSuffixRule * + * @extends Testing\RuleTestCase + * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier */ -final class TestCaseWithSuffixRuleTest extends Test\Integration\AbstractTestCase +final class TestCaseWithSuffixRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'concrete-test-case-with-suffix-test' => __DIR__ . '/../../../../Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ConcreteTestCaseWithSuffixTest.php', - 'explicitly-abstract-test-case' => __DIR__ . '/../../../../Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ExplicitlyAbstractTestCase.php', - 'implicitly-abstract-test-case' => __DIR__ . '/../../../../Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Success/ExplicitlyAbstractTestCase.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testTestCaseWithSuffixRule(): void { - $paths = [ - 'concrete-test-case-extending-abstract-test-case-without-test-suffix' => [ - __DIR__ . '/../../../../Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseExtendingAbstractTestCaseWithoutTestSuffix.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../../../Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule'), + [ [ \sprintf( 'Class %s extends %s, is concrete, but does not have a Test suffix.', - Test\Fixture\Classes\PHPUnit\Framework\TestCaseWithSuffixRule\Failure\ConcreteTestCaseExtendingAbstractTestCaseWithoutTestSuffix::class, + Test\Fixture\Classes\PHPUnit\Framework\TestCaseWithSuffixRule\ConcreteTestCaseExtendingAbstractTestCaseWithoutSuffix::class, Framework\TestCase::class, ), 7, ], - ], - 'concrete-test-case-without-test-suffix' => [ - __DIR__ . '/../../../../Fixture/Classes/PHPUnit/Framework/TestCaseWithSuffixRule/Failure/ConcreteTestCaseWithoutTestSuffix.php', [ \sprintf( 'Class %s extends %s, is concrete, but does not have a Test suffix.', - Test\Fixture\Classes\PHPUnit\Framework\TestCaseWithSuffixRule\Failure\ConcreteTestCaseWithoutTestSuffix::class, + Test\Fixture\Classes\PHPUnit\Framework\TestCaseWithSuffixRule\ConcreteTestCaseWithoutSuffix::class, Framework\TestCase::class, ), 9, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Classes\PHPUnit\Framework\TestCaseWithSuffixRule(self::createReflectionProvider()); diff --git a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php index ae5837d2..a2e61cc9 100644 --- a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php @@ -15,60 +15,37 @@ use Ergebnis\PHPStan\Rules\Closures; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Closures\NoNullableReturnTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoNullableReturnTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoNullableReturnTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'closure-with-return-type-declaration' => __DIR__ . '/../../Fixture/Closures/NoNullableReturnTypeDeclarationRule/Success/closure-with-return-type-declaration.php', - 'closure-function-without-return-type-declaration' => __DIR__ . '/../../Fixture/Closures/NoNullableReturnTypeDeclarationRule/Success/closure-without-return-type-declaration.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoNullableReturnTypeDeclarationRule(): void { - $paths = [ - 'closure-with-nullable-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Closures/NoNullableReturnTypeDeclarationRule/Failure/closure-with-nullable-return-type-declaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Closures/NoNullableReturnTypeDeclarationRule'), + [ [ 'Closure has a nullable return type declaration.', - 7, + 15, ], - ], - 'closure-with-nullable-union-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Closures/NoNullableReturnTypeDeclarationRule/Failure/closure-with-nullable-union-type-return-type-declaration.php', [ 'Closure has a nullable return type declaration.', - 7, + 19, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Closures\NoNullableReturnTypeDeclarationRule(); diff --git a/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php index 2eb841a0..9b3d4847 100644 --- a/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php @@ -15,68 +15,41 @@ use Ergebnis\PHPStan\Rules\Closures; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Closures\NoParameterWithNullDefaultValueRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithNullDefaultValueRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithNullDefaultValueRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'closure-with-parameter-with-non-null-default-value' => __DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule/Success/closure-with-parameter-with-non-null-default-value.php', - 'closure-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule/Success/closure-with-parameter-without-default-value.php', - 'closure-with-parameter-without-parameters' => __DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule/Success/closure-without-parameters.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithNullDefaultValueRule(): void { - $paths = [ - 'closure-with-parameter-with-null-default-value' => [ - __DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule/Failure/closure-with-parameter-with-null-default-value.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule'), + [ [ 'Closure has parameter $bar with null as default value.', - 7, + 18, ], - ], - 'closure-with-parameter-with-root-namespace-referenced-null-default-value' => [ - __DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule/Failure/closure-with-parameter-with-root-namespace-referenced-null-default-value.php', [ 'Closure has parameter $bar with null as default value.', - 7, + 22, ], - ], - 'closure-with-parameter-with-wrongly-capitalized-null-default-value' => [ - __DIR__ . '/../../Fixture/Closures/NoParameterWithNullDefaultValueRule/Failure/closure-with-parameter-with-wrongly-capitalized-null-default-value.php', [ 'Closure has parameter $bar with null as default value.', - 7, + 26, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Closures\NoParameterWithNullDefaultValueRule(); diff --git a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php index 0432bf48..5e6f09dc 100644 --- a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -15,61 +15,37 @@ use Ergebnis\PHPStan\Rules\Closures; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Closures\NoParameterWithNullableTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithNullableTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithNullableTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'closure-with-parameter-with-type-declaration' => __DIR__ . '/../../Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Success/closure-with-parameter-with-type-declaration.php', - 'closure-with-parameter-without-type-declaration' => __DIR__ . '/../../Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Success/closure-with-parameter-without-type-declaration.php', - 'closure-without-parameters' => __DIR__ . '/../../Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Success/closure-without-parameters.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithNullableTypeDeclarationRule(): void { - $paths = [ - 'closure-with-parameter-with-nullable-type-declaration' => [ - __DIR__ . '/../../Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-type-declaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Closures/NoParameterWithNullableTypeDeclarationRule'), + [ [ 'Closure has parameter $bar with a nullable type declaration.', - 7, + 18, ], - ], - 'closure-with-parameter-with-nullable-union-type-declaration' => [ - __DIR__ . '/../../Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/Failure/closure-with-parameter-with-nullable-union-type-declaration.php', [ 'Closure has parameter $bar with a nullable type declaration.', - 7, + 22, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Closures\NoParameterWithNullableTypeDeclarationRule(); diff --git a/test/Integration/Expressions/NoCompactRuleTest.php b/test/Integration/Expressions/NoCompactRuleTest.php index 2b45ab2b..12c86069 100644 --- a/test/Integration/Expressions/NoCompactRuleTest.php +++ b/test/Integration/Expressions/NoCompactRuleTest.php @@ -15,66 +15,41 @@ use Ergebnis\PHPStan\Rules\Expressions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Expressions\NoCompactRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoCompactRuleTest extends Test\Integration\AbstractTestCase +final class NoCompactRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'compact-not-used' => __DIR__ . '/../../Fixture/Expressions/NoCompactRule/Success/compact-not-used.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoCompactRule(): void { - $paths = [ - 'compact-used-with-alias' => [ - __DIR__ . '/../../Fixture/Expressions/NoCompactRule/Failure/compact-used-with-alias.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Expressions/NoCompactRule'), + [ [ 'Function compact() should not be used.', - 12, + 22, ], - ], - 'compact-used-with-correct-case' => [ - __DIR__ . '/../../Fixture/Expressions/NoCompactRule/Failure/compact-used-with-correct-case.php', [ 'Function compact() should not be used.', - 10, + 27, ], - ], - 'compact-used-with-incorrect-case' => [ - __DIR__ . '/../../Fixture/Expressions/NoCompactRule/Failure/compact-used-with-incorrect-case.php', [ 'Function compact() should not be used.', - 10, + 32, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Expressions\NoCompactRule(); diff --git a/test/Integration/Expressions/NoErrorSuppressionRuleTest.php b/test/Integration/Expressions/NoErrorSuppressionRuleTest.php index 6dbbf326..0d6aef40 100644 --- a/test/Integration/Expressions/NoErrorSuppressionRuleTest.php +++ b/test/Integration/Expressions/NoErrorSuppressionRuleTest.php @@ -15,52 +15,33 @@ use Ergebnis\PHPStan\Rules\Expressions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Expressions\NoErrorSuppressionRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoErrorSuppressionRuleTest extends Test\Integration\AbstractTestCase +final class NoErrorSuppressionRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'error-suppression-not-used' => __DIR__ . '/../../Fixture/Expressions/NoErrorSuppressionRule/Success/error-suppression-not-used.php', - ]; + use Test\Util\Helper; - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoErrorSuppressionRule(): void { - $paths = [ - 'error-suppression-used' => [ - __DIR__ . '/../../Fixture/Expressions/NoErrorSuppressionRule/Failure/error-suppression-used.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Expressions/NoErrorSuppressionRule'), + [ [ 'Error suppression via "@" should not be used.', - 7, + 9, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Expressions\NoErrorSuppressionRule(); diff --git a/test/Integration/Expressions/NoEvalRuleTest.php b/test/Integration/Expressions/NoEvalRuleTest.php index 70d0639c..28799d01 100644 --- a/test/Integration/Expressions/NoEvalRuleTest.php +++ b/test/Integration/Expressions/NoEvalRuleTest.php @@ -15,59 +15,37 @@ use Ergebnis\PHPStan\Rules\Expressions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Expressions\NoEvalRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoEvalRuleTest extends Test\Integration\AbstractTestCase +final class NoEvalRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'eval-not-used' => __DIR__ . '/../../Fixture/Expressions/NoEvalRule/Success/eval-not-used.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoEvalRule(): void { - $paths = [ - 'eval-used-with-correct-case' => [ - __DIR__ . '/../../Fixture/Expressions/NoEvalRule/Failure/eval-used-with-correct-case.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Expressions/NoEvalRule'), + [ [ 'Language construct eval() should not be used.', - 7, + 13, ], - ], - 'eval-used-with-incorrect-case' => [ - __DIR__ . '/../../Fixture/Expressions/NoEvalRule/Failure/eval-used-with-incorrect-case.php', [ 'Language construct eval() should not be used.', - 7, + 15, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Expressions\NoEvalRule(); diff --git a/test/Integration/Expressions/NoIssetRuleTest.php b/test/Integration/Expressions/NoIssetRuleTest.php index 24d420e3..3052860c 100644 --- a/test/Integration/Expressions/NoIssetRuleTest.php +++ b/test/Integration/Expressions/NoIssetRuleTest.php @@ -15,59 +15,37 @@ use Ergebnis\PHPStan\Rules\Expressions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Expressions\NoIssetRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoIssetRuleTest extends Test\Integration\AbstractTestCase +final class NoIssetRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'isset-not-used' => __DIR__ . '/../../Fixture/Expressions/NoIssetRule/Success/isset-not-used.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoIssetRule(): void { - $paths = [ - 'isset-used-with-correct-case' => [ - __DIR__ . '/../../Fixture/Expressions/NoIssetRule/Failure/isset-used-with-correct-case.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Expressions/NoIssetRule'), + [ [ 'Language construct isset() should not be used.', - 7, + 16, ], - ], - 'isset-used-with-incorrect-case' => [ - __DIR__ . '/../../Fixture/Expressions/NoIssetRule/Failure/isset-used-with-incorrect-case.php', [ 'Language construct isset() should not be used.', - 7, + 20, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Expressions\NoIssetRule(); diff --git a/test/Integration/Files/DeclareStrictTypesRuleTest.php b/test/Integration/Files/DeclareStrictTypesRuleTest.php index 92d6ffd8..449d4700 100644 --- a/test/Integration/Files/DeclareStrictTypesRuleTest.php +++ b/test/Integration/Files/DeclareStrictTypesRuleTest.php @@ -15,163 +15,89 @@ use Ergebnis\PHPStan\Rules\Files; use Ergebnis\PHPStan\Rules\Test; -use PHPStan\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Files\DeclareStrictTypesRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class DeclareStrictTypesRuleTest extends Test\Integration\AbstractTestCase +final class DeclareStrictTypesRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'file-empty' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-empty.php', - 'file-with-comment-and-declare-strict-types-on' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-comment-and-declare-strict-types-on.php', - 'file-with-comment-and-declare-strict-types-on-and-invalid-casing' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-comment-and-declare-strict-types-on-and-invalid-casing.php', - 'file-with-comment-and-declare-strict-types-on-and-multiple-declares' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-comment-and-declare-strict-types-on-and-multiple-declares.php', - 'file-with-comment-and-declare-strict-types-on-and-namespace-declaration' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-comment-and-declare-strict-types-on-and-namespace-declaration.php', - 'file-with-declare-strict-types-on' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-declare-strict-types-on.php', - 'file-with-declare-strict-types-on-and-invalid-casing' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-declare-strict-types-on-and-invalid-casing.php', - 'file-with-declare-strict-types-on-and-multiple-declares' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-declare-strict-types-on-and-multiple-declares.php', - 'file-with-declare-strict-types-on-and-namespace-declaration' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-declare-strict-types-on-and-namespace-declaration.php', - 'file-with-doc-block-and-declare-strict-types-on' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-doc-block-and-declare-strict-types-on.php', - 'file-with-doc-block-and-declare-strict-types-on-and-invalid-casing' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-doc-block-and-declare-strict-types-on-and-invalid-casing.php', - 'file-with-doc-block-and-declare-strict-types-on-and-multiple-declares' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-doc-block-and-declare-strict-types-on-and-multiple-declares.php', - 'file-with-doc-block-and-declare-strict-types-on-and-namespace-declaration' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-doc-block-and-declare-strict-types-on-and-namespace-declaration.php', - 'file-with-shebang-and-declare-strict-types-on' => __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Success/file-with-shebang-and-declare-strict-types-on.php', - ]; + use Test\Util\Helper; - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testDeclareStrictTypesRule(): void { - $paths = [ - 'file-with-comment-and-declare-strict-types-off' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-comment-and-declare-strict-types-off.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule'), + [ [ 'File is missing a "declare(strict_types=1)" declaration.', 5, ], - ], - 'file-with-comment-and-declare-strict-types-off-and-invalid-casing' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-comment-and-declare-strict-types-off-and-invalid-casing.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 5, ], - ], - 'file-with-comment-and-declare-strict-types-off-and-multiple-declares' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-comment-and-declare-strict-types-off-and-multiple-declares.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 5, ], - ], - 'file-with-declare-strict-types-off' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-declare-strict-types-off.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 3, ], - ], - 'file-with-declare-strict-types-off-and-invalid-casing' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-declare-strict-types-off-and-invalid-casing.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 3, ], - ], - 'file-with-declare-strict-types-off-and-multiple-declares' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-declare-strict-types-off-and-multiple-declares.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 3, ], - ], - 'file-with-declare-ticks' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-declare-ticks.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 3, ], - ], - 'file-with-doc-block-and-declare-strict-types-off' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-doc-block-and-declare-strict-types-off.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 7, ], - ], - 'file-with-doc-block-and-declare-strict-types-off-and-invalid-casing' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-doc-block-and-declare-strict-types-off-and-invalid-casing.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 7, ], - ], - 'file-with-doc-block-and-declare-strict-types-off-and-multiple-declares' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-doc-block-and-declare-strict-types-off-and-multiple-declares.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 7, ], - ], - 'file-with-shebang-and-another-one-text-line-before-opening-tag' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-shebang-and-another-one-text-line-before-opening-tag.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 1, ], - ], - 'file-with-shebang-and-declare-strict-types-off' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-shebang-and-declare-strict-types-off.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 1, ], - ], - 'file-with-text-before-opening-tag' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-with-text-before-opening-tag.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 1, ], - ], - 'file-without-declare-strict-types-and-namespace-declaration' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-without-declare-strict-types-and-namespace-declaration.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 3, ], - ], - 'file-without-declare-strict-types' => [ - __DIR__ . '/../../Fixture/Files/DeclareStrictTypesRule/Failure/file-without-declare-strict-types.php', [ 'File is missing a "declare(strict_types=1)" declaration.', 3, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Files\DeclareStrictTypesRule(); diff --git a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php index 64fc5017..c1d94b7e 100644 --- a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php @@ -15,60 +15,37 @@ use Ergebnis\PHPStan\Rules\Functions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Functions\NoNullableReturnTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoNullableReturnTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoNullableReturnTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'function-with-return-type-declaration' => __DIR__ . '/../../Fixture/Functions/NoNullableReturnTypeDeclarationRule/Success/function-with-return-type-declaration.php', - 'function-without-return-type-declaration' => __DIR__ . '/../../Fixture/Functions/NoNullableReturnTypeDeclarationRule/Success/function-without-return-type-declaration.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoNullableReturnTypeDeclarationRule(): void { - $paths = [ - 'function-with-nullable-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Functions/NoNullableReturnTypeDeclarationRule/Failure/function-with-nullable-return-type-declaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Functions/NoNullableReturnTypeDeclarationRule'), + [ [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\Failure\foo() has a nullable return type declaration.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\baz() has a nullable return type declaration.', + 17, ], - ], - 'function-with-nullable-union-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Functions/NoNullableReturnTypeDeclarationRule/Failure/function-with-nullable-union-return-type-declaration.php', [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\Failure\foo() has a nullable return type declaration.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\quux() has a nullable return type declaration.', + 22, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Functions\NoNullableReturnTypeDeclarationRule(); diff --git a/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php index 84f2dc40..62753184 100644 --- a/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php @@ -15,68 +15,41 @@ use Ergebnis\PHPStan\Rules\Functions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullDefaultValueRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithNullDefaultValueRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithNullDefaultValueRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'function-with-parameter-with-non-null-default-value' => __DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule/Success/function-with-parameter-with-non-null-default-value.php', - 'function-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule/Success/function-with-parameter-without-default-value.php', - 'function-without-parameters' => __DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule/Success/function-without-parameters.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithNullDefaultValueRule(): void { - $paths = [ - 'function-with-parameter-with-null-default-value' => [ - __DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule/Failure/function-with-parameter-with-null-default-value.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule'), + [ [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullDefaultValueRule\Failure\foo() has parameter $bar with null as default value.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullDefaultValueRule\qux() has parameter $bar with null as default value.', + 21, ], - ], - 'function-with-parameter-with-root-namespace-referenced-null-default-value' => [ - __DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule/Failure/function-with-parameter-with-root-namespace-referenced-null-default-value.php', [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullDefaultValueRule\Failure\foo() has parameter $bar with null as default value.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullDefaultValueRule\quux() has parameter $bar with null as default value.', + 26, ], - ], - 'function-with-parameter-with-wrongly-capitalized-null-default-value' => [ - __DIR__ . '/../../Fixture/Functions/NoParameterWithNullDefaultValueRule/Failure/function-with-parameter-with-wrongly-capitalized-null-default-value.php', [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullDefaultValueRule\Failure\foo() has parameter $bar with null as default value.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullDefaultValueRule\quz() has parameter $bar with null as default value.', + 31, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Functions\NoParameterWithNullDefaultValueRule(); diff --git a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php index 65d7c613..031ab514 100644 --- a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -15,61 +15,37 @@ use Ergebnis\PHPStan\Rules\Functions; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullableTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithNullableTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithNullableTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'function-with-parameter-with-type-declaration' => __DIR__ . '/../../Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Success/function-with-parameter-with-type-declaration.php', - 'function-with-parameter-without-type-declaration' => __DIR__ . '/../../Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Success/function-with-parameter-without-type-declaration.php', - 'function-without-parameters' => __DIR__ . '/../../Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Success/function-without-parameters.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithNullableTypeDeclarationRule(): void { - $paths = [ - 'function-with-parameter-with-nullable-type-declaration' => [ - __DIR__ . '/../../Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Failure/function-with-parameter-with-nullable-type-declaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Functions/NoParameterWithNullableTypeDeclarationRule'), + [ [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\Failure\foo() has parameter $bar with a nullable type declaration.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\qux() has parameter $bar with a nullable type declaration.', + 21, ], - ], - 'function-with-parameter-with-nullable-union-type-declaration' => [ - __DIR__ . '/../../Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/Failure/function-with-parameter-with-nullable-union-type-declaration.php', [ - 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\Failure\foo() has parameter $bar with a nullable type declaration.', - 7, + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\quux() has parameter $bar with a nullable type declaration.', + 26, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Functions\NoParameterWithNullableTypeDeclarationRule(); diff --git a/test/Integration/Methods/FinalInAbstractClassRuleTest.php b/test/Integration/Methods/FinalInAbstractClassRuleTest.php index 40525595..30bf976e 100644 --- a/test/Integration/Methods/FinalInAbstractClassRuleTest.php +++ b/test/Integration/Methods/FinalInAbstractClassRuleTest.php @@ -15,98 +15,43 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Methods\FinalInAbstractClassRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class FinalInAbstractClassRuleTest extends Test\Integration\AbstractTestCase +final class FinalInAbstractClassRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'abstract-class-with-abstract-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithAbstractMethod.php', - 'abstract-class-with-final-protected-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithFinalProtectedMethod.php', - 'abstract-class-with-final-public-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithFinalPublicMethod.php', - 'abstract-class-with-non-final-constructor' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithNonFinalConstructor.php', - 'abstract-class-with-private-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPrivateMethod.php', - 'abstract-class-with-protected-method-and-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInInlineDocBlock.php', - 'abstract-class-with-protected-method-and-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAnnotationInMultilineDocBlock.php', - 'abstract-class-with-protected-method-and-embeddable-attribute' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEmbeddableAttribute.php', - 'abstract-class-with-protected-method-and-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEntityAnnotationInInlineDocBlock.php', - 'abstract-class-with-protected-method-and-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEntityAnnotationInMultilineDocBlock.php', - 'abstract-class-with-protected-method-and-entity-attribute' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndEntityAttribute.php', - 'abstract-class-with-protected-method-and-orm-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEmbeddableAnnotationInMultilineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEmbeddableAnnotationInInlineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEntityAnnotationInMultilineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmEntityAnnotationInInlineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-mapping-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEmbeddableAnnotationInInlineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-mapping-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEmbeddableAnnotationInMultilineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-mapping-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEntityAnnotationInInlineDocBlock.php', - 'abstract-class-with-protected-method-and-orm-mapping-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithProtectedMethodAndOrmMappingEntityAnnotationInMultilineDocBlock.php', - 'abstract-class-with-public-method-and-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEmbeddableAnnotationInInlineDocBlock.php', - 'abstract-class-with-public-method-and-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEmbeddableAnnotationInMultilineDocBlock.php', - 'abstract-class-with-public-method-and-embeddable-attribute' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEmbeddableAttribute.php', - 'abstract-class-with-public-method-and-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEntityAnnotationInInlineDocBlock.php', - 'abstract-class-with-public-method-and-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEntityAnnotationInMultilineDocBlock.php', - 'abstract-class-with-public-method-and-entity-attribute' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndEntityAttribute.php', - 'abstract-class-with-public-method-and-orm-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEmbeddableAnnotationInMultilineDocBlock.php', - 'abstract-class-with-public-method-and-orm-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEmbeddableAnnotationInInlineDocBlock.php', - 'abstract-class-with-public-method-and-orm-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEntityAnnotationInMultilineDocBlock.php', - 'abstract-class-with-public-method-and-orm-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmEntityAnnotationInInlineDocBlock.php', - 'abstract-class-with-public-method-and-orm-mapping-embeddable-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEmbeddableAnnotationInInlineDocBlock.php', - 'abstract-class-with-public-method-and-orm-mapping-embeddable-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEmbeddableAnnotationInMultilineDocBlock.php', - 'abstract-class-with-public-method-and-orm-mapping-entity-annotation-in-inline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEntityAnnotationInInlineDocBlock.php', - 'abstract-class-with-public-method-and-orm-mapping-entity-annotation-in-multiline-doc-block' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/AbstractClassWithPublicMethodAndOrmMappingEntityAnnotationInMultilineDocBlock.php', - 'interface-with-public-method' => __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Success/InterfaceWithPublicMethod.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testFinalInAbstractClassRule(): void { - $paths = [ - 'abstract-class-with-protected-method' => [ - __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Failure/AbstractClassWithProtectedMethod.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule'), + [ [ \sprintf( 'Method %s::method() is not final, but since the containing class is abstract, it should be.', - Test\Fixture\Methods\FinalInAbstractClassRule\Failure\AbstractClassWithProtectedMethod::class, + Test\Fixture\Methods\FinalInAbstractClassRule\AbstractClassWithProtectedMethod::class, ), 9, ], - ], - 'abstract-class-with-public-method' => [ - __DIR__ . '/../../Fixture/Methods/FinalInAbstractClassRule/Failure/AbstractClassWithPublicMethod.php', [ \sprintf( 'Method %s::method() is not final, but since the containing class is abstract, it should be.', - Test\Fixture\Methods\FinalInAbstractClassRule\Failure\AbstractClassWithPublicMethod::class, + Test\Fixture\Methods\FinalInAbstractClassRule\AbstractClassWithPublicMethod::class, ), 9, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\FinalInAbstractClassRule(); diff --git a/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php b/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php index 59687e38..6edbfcef 100644 --- a/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php +++ b/test/Integration/Methods/NoConstructorParameterWithDefaultValueRuleTest.php @@ -15,90 +15,51 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Methods\NoConstructorParameterWithDefaultValueRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoConstructorParameterWithDefaultValueRuleTest extends Test\Integration\AbstractTestCase +final class NoConstructorParameterWithDefaultValueRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'constructor-in-anonymous-class-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/constructor-in-anonymous-class-with-parameter-without-default-value.php', - 'constructor-in-anonymous-class-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/constructor-in-anonymous-class-without-parameters.php', - 'constructor-in-class-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/ConstructorInClassWithParameterWithoutDefaultValue.php', - 'constructor-in-class-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/ConstructorInClassWithoutParameters.php', - // traits are not supported - 'constructor-in-trait-with-parameter-with-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/ConstructorInTraitWithParameterWithDefaultValue.php', - 'constructor-in-trait-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/ConstructorInTraitWithParameterWithoutDefaultValue.php', - 'constructor-in-trait-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/ConstructorInTraitWithoutParameters.php', - // non-constructor-methods - 'method-in-anonymous-class-with-parameter-with-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/method-in-anonymous-class-with-parameter-with-default-value.php', - 'method-in-class-with-parameter-with-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/MethodInClassWithParameterWithDefaultValue.php', - 'method-in-trait-with-parameter-with-default-value' => __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Success/MethodInTraitWithParameterWithDefaultValue.php', - ]; + use Test\Util\Helper; - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoConstructorParameterWithDefaultValueRule(): void { - $paths = [ - 'constructor-in-anonymous-class-with-parameter-with-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Failure/constructor-in-anonymous-class-with-parameter-with-default-value.php', - [ - 'Constructor in anonymous class has parameter $bar with default value.', - 8, - ], - ], - 'constructor-with-wrong-capitalization-in-anonymous-class-with-parameter-with-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Failure/constructor-with-wrong-capitalization-in-anonymous-class-with-parameter-with-default-value.php', - [ - 'Constructor in anonymous class has parameter $bar with default value.', - 8, - ], - ], - 'constructor-in-class-with-parameter-with-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Failure/ConstructorInClassWithParameterWithDefaultValue.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule'), + [ [ \sprintf( 'Constructor in %s has parameter $bar with default value.', - Test\Fixture\Methods\NoConstructorParameterWithDefaultValueRule\Failure\ConstructorInClassWithParameterWithDefaultValue::class, + Test\Fixture\Methods\NoConstructorParameterWithDefaultValueRule\ConstructorInClassWithParameterWithDefaultValue::class, ), 9, ], - ], - 'constructor-with-wrong-capitalization-in-class-with-parameter-with-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoConstructorParameterWithDefaultValueRule/Failure/ConstructorWithWrongCapitalizationInClassWithParameterWithDefaultValue.php', [ \sprintf( 'Constructor in %s has parameter $bar with default value.', - Test\Fixture\Methods\NoConstructorParameterWithDefaultValueRule\Failure\ConstructorWithWrongCapitalizationInClassWithParameterWithDefaultValue::class, + Test\Fixture\Methods\NoConstructorParameterWithDefaultValueRule\ConstructorWithWrongCapitalizationInClassWithParameterWithDefaultValue::class, ), 9, ], + [ + 'Constructor in anonymous class has parameter $bar with default value.', + 26, + ], + [ + 'Constructor in anonymous class has parameter $bar with default value.', + 32, + ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\NoConstructorParameterWithDefaultValueRule(); diff --git a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php index 29bf375c..a565a4b7 100644 --- a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php @@ -15,108 +15,65 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Methods\NoNullableReturnTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoNullableReturnTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoNullableReturnTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'method-in-anonymous-class-with-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInAnonymousClassWithReturnTypeDeclaration.php', - 'method-in-anonymous-class-without-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInAnonymousClassWithoutReturnTypeDeclaration.php', - 'method-in-class-with-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInClassWithReturnTypeDeclaration.php', - 'method-in-class-without-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInClassWithoutReturnTypeDeclaration.php', - 'method-in-interface-with-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInInterfaceWithReturnTypeDeclaration.php', - 'method-in-interface-without-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInInterfaceWithoutReturnTypeDeclaration.php', - // traits are currently not supported - 'method-in-trait-with-nullable-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInTraitWithNullableReturnTypeDeclaration.php', - 'method-in-trait-with-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInTraitWithReturnTypeDeclaration.php', - 'method-in-trait-without-return-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Success/MethodInTraitWithoutReturnTypeDeclaration.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoNullableReturnTypeDeclarationRule(): void { - $paths = [ - 'method-in-anonymous-class-with-nullable-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInAnonymousClassWithNullableReturnTypeDeclaration.php', - [ - 'Method toString() in anonymous class has a nullable return type declaration.', - 12, - ], - ], - 'method-in-anonymous-class-with-nullable-union-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInAnonymousClassWithNullableUnionReturnTypeDeclaration.php', - [ - 'Method toString() in anonymous class has a nullable return type declaration.', - 12, - ], - ], - 'method-in-class-with-nullable-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInClassWithNullableReturnTypeDeclaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule'), + [ [ \sprintf( 'Method %s::toString() has a nullable return type declaration.', - Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\Failure\MethodInClassWithNullableReturnTypeDeclaration::class, + Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\MethodInClassWithNullableReturnTypeDeclaration::class, ), 9, ], - ], - 'method-in-class-with-nullable-union-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInClassWithNullableUnionReturnTypeDeclaration.php', [ \sprintf( 'Method %s::toString() has a nullable return type declaration.', - Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\Failure\MethodInClassWithNullableUnionReturnTypeDeclaration::class, + Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\MethodInClassWithNullableUnionReturnTypeDeclaration::class, ), 9, ], - ], - 'method-in-interface-with-nullable-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInInterfaceWithNullableReturnTypeDeclaration.php', [ \sprintf( 'Method %s::toString() has a nullable return type declaration.', - Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\Failure\MethodInInterfaceWithNullableReturnTypeDeclaration::class, + Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\MethodInInterfaceWithNullableReturnTypeDeclaration::class, ), 9, ], - ], - 'method-in-interface-with-nullable-union-return-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoNullableReturnTypeDeclarationRule/Failure/MethodInInterfaceWithNullableUnionReturnTypeDeclaration.php', [ \sprintf( 'Method %s::toString() has a nullable return type declaration.', - Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\Failure\MethodInInterfaceWithNullableUnionReturnTypeDeclaration::class, + Test\Fixture\Methods\NoNullableReturnTypeDeclarationRule\MethodInInterfaceWithNullableUnionReturnTypeDeclaration::class, ), 9, ], + [ + 'Method toString() in anonymous class has a nullable return type declaration.', + 22, + ], + [ + 'Method toString() in anonymous class has a nullable return type declaration.', + 29, + ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\NoNullableReturnTypeDeclarationRule(); diff --git a/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php b/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php index bfb4558f..a70fd387 100644 --- a/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoParameterWithContainerTypeDeclarationRuleTest.php @@ -15,139 +15,91 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; use Psr\Container; /** * @covers \Ergebnis\PHPStan\Rules\Methods\NoParameterWithContainerTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithContainerTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithContainerTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'anonymous-class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration-where-name-is-excluded' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/anonymous-class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration-where-name-is-excluded.php', - 'anonymous-class-with-method-with-parameter-with-other-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/anonymous-class-with-method-with-parameter-with-other-type-declaration.php', - 'anonymous-class-with-method-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/anonymous-class-with-method-without-parameter.php', - 'class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration-where-name-is-excluded' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/ClassWithMethodWithParameterWithClassImplementingContainerInterfaceAsTypeDeclarationWhereNameIsExcluded.php', - 'class-with-method-with-parameter-with-other-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/ClassWithMethodWithParameterWithOtherTypeDeclaration.php', - 'class-with-method-without-parameter' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/ClassWithMethodWithoutParameter.php', - 'interface-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration-where-name-is-excluded' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/InterfaceWithMethodWithParameterWithContainerInterfaceAsTypeDeclarationWhereNameIsExcluded.php', - 'interface-with-method-with-parameter-with-other-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/InterfaceWithMethodWithParameterWithOtherTypeDeclaration.php', - 'interface-with-method-without-parameter' => __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Success/InterfaceWithMethodWithoutParameter.php', - ]; + use Test\Util\Helper; - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } - - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithContainerTypeDeclarationRuleTest(): void { - $paths = [ - 'anonymous-class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/anonymous-class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration.php', - [ - \sprintf( - 'Method __construct() in anonymous class has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassImplementingContainerInterface::class, - ), - 9, - ], - ], - 'anonymous-class-with-method-with-parameter-with-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/anonymous-class-with-method-with-parameter-with-container-interface-as-type-declaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule'), + [ [ \sprintf( - 'Method __construct() in anonymous class has a parameter $container with a type declaration of %s, but containers should not be injected.', - Container\ContainerInterface::class, + 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassImplementingContainerInterfaceWithMethodWithParameterWithSelfAsTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassImplementingContainerInterfaceWithMethodWithParameterWithSelfAsTypeDeclaration::class, ), 11, ], - ], - 'anonymous-class-with-method-with-parameter-with-interface-extending-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/anonymous-class-with-method-with-parameter-with-interface-extending-container-interface-as-type-declaration.php', [ \sprintf( - 'Method __construct() in anonymous class has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\InterfaceExtendingContainerInterface::class, + 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassWithMethodWithParameterWithClassImplementingContainerInterfaceAsTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassImplementingContainerInterface::class, ), 9, ], - ], - 'class-implementing-container-interface-with-method-with-parameter-with-self-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/ClassImplementingContainerInterfaceWithMethodWithParameterWithSelfAsTypeDeclaration.php', [ \sprintf( 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassImplementingContainerInterfaceWithMethodWithParameterWithSelfAsTypeDeclaration::class, - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassImplementingContainerInterfaceWithMethodWithParameterWithSelfAsTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration::class, + Container\ContainerInterface::class, ), 11, ], - ], - 'class-with-method-with-parameter-with-class-implementing-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/ClassWithMethodWithParameterWithClassImplementingContainerInterfaceAsTypeDeclaration.php', [ \sprintf( 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassWithMethodWithParameterWithClassImplementingContainerInterfaceAsTypeDeclaration::class, - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassImplementingContainerInterface::class, + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassWithMethodWithParameterWithInterfaceExtendingContainerInterfaceAsTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\InterfaceExtendingContainerInterface::class, ), 9, ], - ], - 'class-with-method-with-parameter-with-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/ClassWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration.php', [ \sprintf( 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\InterfaceWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration::class, Container\ContainerInterface::class, ), 11, ], - ], - 'class-with-method-with-parameter-with-interface-extending-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/ClassWithMethodWithParameterWithInterfaceExtendingContainerInterfaceAsTypeDeclaration.php', [ \sprintf( - 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\ClassWithMethodWithParameterWithInterfaceExtendingContainerInterfaceAsTypeDeclaration::class, - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\InterfaceExtendingContainerInterface::class, + 'Method __construct() in anonymous class has a parameter $container with a type declaration of %s, but containers should not be injected.', + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\ClassImplementingContainerInterface::class, ), - 9, + 29, ], - ], - 'interface-with-method-with-parameter-with-container-interface-as-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithContainerTypeDeclarationRule/Failure/InterfaceWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration.php', [ \sprintf( - 'Method %s::method() has a parameter $container with a type declaration of %s, but containers should not be injected.', - Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\Failure\InterfaceWithMethodWithParameterWithContainerInterfaceAsTypeDeclaration::class, + 'Method __construct() in anonymous class has a parameter $container with a type declaration of %s, but containers should not be injected.', Container\ContainerInterface::class, ), - 11, + 36, + ], + [ + \sprintf( + 'Method __construct() in anonymous class has a parameter $container with a type declaration of %s, but containers should not be injected.', + Test\Fixture\Methods\NoParameterWithContainerTypeDeclarationRule\InterfaceExtendingContainerInterface::class, + ), + 43, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\NoParameterWithContainerTypeDeclarationRule( diff --git a/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php index 5ffc0c92..6783d93b 100644 --- a/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php @@ -15,141 +15,83 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Methods\NoParameterWithNullDefaultValueRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithNullDefaultValueRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithNullDefaultValueRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'method-in-anonymous-class-with-parameter-with-non-null-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/method-in-anonymous-class-with-parameter-with-non-null-default-value.php', - 'method-in-anonymous-class-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/method-in-anonymous-class-with-parameter-without-default-value.php', - 'method-in-anonymous-class-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/method-in-anonymous-class-without-parameters.php', - 'method-in-class-with-parameter-with-non-null-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInClassWithParameterWithNonNullDefaultValue.php', - 'method-in-class-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInClassWithParameterWithoutDefaultValue.php', - 'method-in-class-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInClassWithoutParameters.php', - 'method-in-interface-with-parameter-with-non-null-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInInterfaceWithParameterWithNonNullDefaultValue.php', - 'method-in-interface-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInInterfaceWithParameterWithoutDefaultValue.php', - 'method-in-interface-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInInterfaceWithoutParameters.php', - // traits are not supported - 'method-in-trait-with-parameter-with-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInTraitWithParameterWithDefaultValue.php', - 'method-in-trait-with-parameter-with-non-null-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInTraitWithParameterWithNonNullDefaultValue.php', - 'method-in-trait-with-parameter-with-root-namespace-referenced-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInTraitWithParameterWithRootNamespaceReferencedNullDefaultValue.php', - 'method-in-trait-with-parameter-with-wrongly-capitalized-null-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInTraitWithParameterWithWronlgyCapitalizedNullDefaultValue.php', - 'method-in-trait-with-parameter-without-default-value' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInTraitWithParameterWithoutDefaultValue.php', - 'method-in-trait-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Success/MethodInTraitWithoutParameters.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithNullDefaultValueRule(): void { - $paths = [ - 'method-in-anonymous-class-with-parameter-with-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/method-in-anonymous-class-with-parameter-with-null-default-value.php', - [ - 'Method foo() in anonymous class has parameter $bar with null as default value.', - 8, - ], - ], - 'method-in-anonymous-class-with-parameter-with-root-namespace-referenced-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/method-in-anonymous-class-with-parameter-with-root-namespace-referenced-null-default-value.php', - [ - 'Method foo() in anonymous class has parameter $bar with null as default value.', - 8, - ], - ], - 'method-in-anonymous-class-with-parameter-with-wrongly-capitalized-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/method-in-anonymous-class-with-parameter-with-wrongly-capitalized-null-default-value.php', - [ - 'Method foo() in anonymous class has parameter $bar with null as default value.', - 8, - ], - ], - 'method-in-class-with-parameter-with-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/MethodInClassWithParameterWithNullDefaultValue.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule'), + [ [ \sprintf( 'Method %s::foo() has parameter $bar with null as default value.', - Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\Failure\MethodInClassWithParameterWithNullDefaultValue::class, + Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\MethodInClassWithParameterWithNullDefaultValue::class, ), 9, ], - ], - 'method-in-class-with-parameter-with-root-namespace-referenced-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/MethodInClassWithParameterWithRootNamespaceReferencedNullDefaultValue.php', [ \sprintf( 'Method %s::foo() has parameter $bar with null as default value.', - Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\Failure\MethodInClassWithParameterWithRootNamespaceReferencedNullDefaultValue::class, + Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\MethodInClassWithParameterWithRootNamespaceReferencedNullDefaultValue::class, ), 9, ], - ], - 'method-in-class-with-parameter-with-wrongly-capitalized-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/MethodInClassWithParameterWithWronglyCapitalizedNullDefaultValue.php', [ \sprintf( 'Method %s::foo() has parameter $bar with null as default value.', - Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\Failure\MethodInClassWithParameterWithWronglyCapitalizedNullDefaultValue::class, + Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\MethodInClassWithParameterWithWronglyCapitalizedNullDefaultValue::class, ), 9, ], - ], - 'method-in-interface-with-parameter-with-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/MethodInInterfaceWithParameterWithNullDefaultValue.php', [ \sprintf( 'Method %s::foo() has parameter $bar with null as default value.', - Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\Failure\MethodInInterfaceWithParameterWithNullDefaultValue::class, + Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\MethodInInterfaceWithParameterWithNullDefaultValue::class, ), 9, ], - ], - 'method-in-interface-with-parameter-with-root-namespace-referenced-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/MethodInInterfaceWithParameterWithRootNamespaceReferencedNullDefaultValue.php', [ \sprintf( 'Method %s::foo() has parameter $bar with null as default value.', - Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\Failure\MethodInInterfaceWithParameterWithRootNamespaceReferencedNullDefaultValue::class, + Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\MethodInInterfaceWithParameterWithRootNamespaceReferencedNullDefaultValue::class, ), 9, ], - ], - 'method-in-interface-with-parameter-wrongly-capitalized-null-default-value' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullDefaultValueRule/Failure/MethodInInterfaceWithParameterWithWronlgyCapitalizedNullDefaultValue.php', [ \sprintf( 'Method %s::foo() has parameter $bar with null as default value.', - Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\Failure\MethodInInterfaceWithParameterWithWronlgyCapitalizedNullDefaultValue::class, + Test\Fixture\Methods\NoParameterWithNullDefaultValueRule\MethodInInterfaceWithParameterWithWronlgyCapitalizedNullDefaultValue::class, ), 9, ], + [ + 'Method foo() in anonymous class has parameter $bar with null as default value.', + 28, + ], + [ + 'Method foo() in anonymous class has parameter $bar with null as default value.', + 35, + ], + [ + 'Method foo() in anonymous class has parameter $bar with null as default value.', + 42, + ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\NoParameterWithNullDefaultValueRule(); diff --git a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php index c488bb9b..c4f81442 100644 --- a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -15,111 +15,65 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Methods\NoParameterWithNullableTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class NoParameterWithNullableTypeDeclarationRuleTest extends Test\Integration\AbstractTestCase +final class NoParameterWithNullableTypeDeclarationRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'method-in-anonymous-class-with-parameter-with-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/method-in-anonymous-class-with-parameter-with-type-declaration.php', - 'method-in-anonymous-class-with-parameter-without-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/method-in-anonymous-class-with-parameter-without-type-declaration.php', - 'method-in-anonymous-class-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/method-in-anonymous-class-without-parameters.php', - 'method-in-class-with-parameter-with-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInClassWithParameterWithTypeDeclaration.php', - 'method-in-class-with-parameter-without-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInClassWithParameterWithoutTypeDeclaration.php', - 'method-in-class-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInClassWithoutParameters.php', - 'method-in-interface-with-parameter-with-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInInterfaceWithParameterWithTypeDeclaration.php', - 'method-in-interface-with-parameter-without-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInInterfaceWithParameterWithoutTypeDeclaration.php', - 'method-in-interface-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInInterfaceWithoutParameters.php', - // traits are not supported - 'method-in-trait-with-parameter-with-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInTraitWithParameterWithTypeDeclaration.php', - 'method-in-trait-with-parameter-without-type-declaration' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInTraitWithParameterWithoutTypeDeclaration.php', - 'method-in-trait-without-parameters' => __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Success/MethodInTraitWithoutParameters.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoParameterWithNullableTypeDeclarationRule(): void { - $paths = [ - 'method-in-anonymous-class-with-parameter-with-nullable-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/method-in-anonymous-class-with-parameter-with-nullable-type-declaration.php', - [ - 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', - 8, - ], - ], - 'method-in-anonymous-class-with-parameter-with-nullable-union-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/method-in-anonymous-class-with-parameter-with-nullable-union-type-declaration.php', - [ - 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', - 8, - ], - ], - 'method-in-class-with-parameter-with-nullable-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/MethodInClassWithParameterWithNullableTypeDeclaration.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule'), + [ [ \sprintf( 'Method %s::foo() has parameter $bar with a nullable type declaration.', - Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\Failure\MethodInClassWithParameterWithNullableTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\MethodInClassWithParameterWithNullableTypeDeclaration::class, ), 9, ], - ], - 'method-in-class-with-parameter-with-nullable-union-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/MethodInClassWithParameterWithNullableUnionTypeDeclaration.php', [ \sprintf( 'Method %s::foo() has parameter $bar with a nullable type declaration.', - Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\Failure\MethodInClassWithParameterWithNullableUnionTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\MethodInClassWithParameterWithNullableUnionTypeDeclaration::class, ), 9, ], - ], - 'method-in-interface-with-parameter-with-nullable-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/MethodInInterfaceWithParameterWithNullableTypeDeclaration.php', [ \sprintf( 'Method %s::foo() has parameter $bar with a nullable type declaration.', - Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\Failure\MethodInInterfaceWithParameterWithNullableTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\MethodInInterfaceWithParameterWithNullableTypeDeclaration::class, ), 9, ], - ], - 'method-in-interface-with-parameter-with-nullable-union-type-declaration' => [ - __DIR__ . '/../../Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/Failure/MethodInInterfaceWithParameterWithNullableUnionTypeDeclaration.php', [ \sprintf( 'Method %s::foo() has parameter $bar with a nullable type declaration.', - Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\Failure\MethodInInterfaceWithParameterWithNullableUnionTypeDeclaration::class, + Test\Fixture\Methods\NoParameterWithNullableTypeDeclarationRule\MethodInInterfaceWithParameterWithNullableUnionTypeDeclaration::class, ), 9, ], + [ + 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', + 28, + ], + [ + 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', + 35, + ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\NoParameterWithNullableTypeDeclarationRule(); diff --git a/test/Integration/Methods/PrivateInFinalClassRuleTest.php b/test/Integration/Methods/PrivateInFinalClassRuleTest.php index 41436b14..e00391b5 100644 --- a/test/Integration/Methods/PrivateInFinalClassRuleTest.php +++ b/test/Integration/Methods/PrivateInFinalClassRuleTest.php @@ -15,68 +15,47 @@ use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Methods\PrivateInFinalClassRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier + * + * @extends Testing\RuleTestCase */ -final class PrivateInFinalClassRuleTest extends Test\Integration\AbstractTestCase +final class PrivateInFinalClassRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'abstract-class-with-protected-method' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/AbstractClassWithProtectedMethod.php', - 'class-with-protected-method' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/ClassWithProtectedMethod.php', - 'final-class-with-private-method' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/FinalClassWithPrivateMethod.php', - 'final-class-with-protected-method-extending-class-extending-class-with-same-protected-method' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/FinalClassWithProtectedMethodExtendingClassExtendingClassWithSameProtectedMethod.php', - 'final-class-with-protected-method-extending-class-with-same-protected-method' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/FinalClassWithProtectedMethodExtendingClassWithSameProtectedMethod.php', - 'final-class-with-protected-method-from-trait' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/FinalClassWithProtectedMethodFromTrait.php', - 'final-class-with-public-method' => __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Success/FinalClassWithPublicMethod.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testPrivateInFinalClassRule(): void { - $paths = [ - 'anonymous-class-with-protected-method' => [ - __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Failure/AnonymousClassWithProtectedMethod.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule'), + [ [ - 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', - 8, + \sprintf( + 'Method %s::method() is protected, but since the containing class is final, it can be private.', + Test\Fixture\Methods\PrivateInFinalClassRule\FinalClassWithProtectedMethod::class, + ), + 9, ], - ], - 'final-class-with-protected-method' => [ - __DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule/Failure/FinalClassWithProtectedMethod.php', [ \sprintf( 'Method %s::method() is protected, but since the containing class is final, it can be private.', - Test\Fixture\Methods\PrivateInFinalClassRule\Failure\FinalClassWithProtectedMethod::class, + Test\Fixture\Methods\PrivateInFinalClassRule\FinalClassWithProtectedMethodFromTrait::class, ), 9, ], + [ + 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', + 8, + ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Methods\PrivateInFinalClassRule(); diff --git a/test/Integration/Statements/NoSwitchRuleTest.php b/test/Integration/Statements/NoSwitchRuleTest.php index 24e62d77..eb615f5d 100644 --- a/test/Integration/Statements/NoSwitchRuleTest.php +++ b/test/Integration/Statements/NoSwitchRuleTest.php @@ -15,59 +15,37 @@ use Ergebnis\PHPStan\Rules\Statements; use Ergebnis\PHPStan\Rules\Test; -use PhpParser\Node; use PHPStan\Rules; +use PHPStan\Testing; /** * @covers \Ergebnis\PHPStan\Rules\Statements\NoSwitchRule * + * @extends \PHPStan\Testing\RuleTestCase + * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier */ -final class NoSwitchRuleTest extends Test\Integration\AbstractTestCase +final class NoSwitchRuleTest extends Testing\RuleTestCase { - public static function provideCasesWhereAnalysisShouldSucceed(): iterable - { - $paths = [ - 'isset-not-used' => __DIR__ . '/../../Fixture/Statements/NoSwitchRule/Success/switch-not-used.php', - ]; - - foreach ($paths as $description => $path) { - yield $description => [ - $path, - ]; - } - } + use Test\Util\Helper; - public static function provideCasesWhereAnalysisShouldFail(): iterable + public function testNoSwitchRule(): void { - $paths = [ - 'switch-used-with-correct-case' => [ - __DIR__ . '/../../Fixture/Statements/NoSwitchRule/Failure/switch-used-with-correct-case.php', + $this->analyse( + self::phpFilesIn(__DIR__ . '/../../Fixture/Statements/NoSwitchRule'), + [ [ 'Control structures using switch should not be used.', 7, ], - ], - 'switch-used-with-incorrect-case' => [ - __DIR__ . '/../../Fixture/Statements/NoSwitchRule/Failure/switch-used-with-incorrect-case.php', [ 'Control structures using switch should not be used.', 7, ], ], - ]; - - foreach ($paths as $description => [$path, $error]) { - yield $description => [ - $path, - $error, - ]; - } + ); } - /** - * @return Rules\Rule - */ protected function getRule(): Rules\Rule { return new Statements\NoSwitchRule(); diff --git a/test/Util/Helper.php b/test/Util/Helper.php new file mode 100644 index 00000000..ec2004da --- /dev/null +++ b/test/Util/Helper.php @@ -0,0 +1,35 @@ + + */ + private static function phpFilesIn(string $directory): array + { + $finder = Finder\Finder::create() + ->files() + ->in($directory) + ->name('/\.php$/') + ->sortByName(); + + return \array_map(static function (Finder\SplFileInfo $fileInfo): string { + return $fileInfo->getPathname(); + }, \iterator_to_array($finder, false)); + } +} From 89810af5ed1a1dd5965f6ad4d0e5754205c65c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 11:49:34 +0100 Subject: [PATCH 69/93] Fix: Add test case Related to #838. --- ...mplementingAbstractProtectedMethodFromTrait.php | 14 ++++++++++++++ .../TraitWithAbstractProtectedMethod.php | 10 ++++++++++ .../Methods/PrivateInFinalClassRuleTest.php | 7 +++++++ 3 files changed, 31 insertions(+) create mode 100644 test/Fixture/Methods/PrivateInFinalClassRule/FinalClassImplementingAbstractProtectedMethodFromTrait.php create mode 100644 test/Fixture/Methods/PrivateInFinalClassRule/TraitWithAbstractProtectedMethod.php diff --git a/test/Fixture/Methods/PrivateInFinalClassRule/FinalClassImplementingAbstractProtectedMethodFromTrait.php b/test/Fixture/Methods/PrivateInFinalClassRule/FinalClassImplementingAbstractProtectedMethodFromTrait.php new file mode 100644 index 00000000..878365ed --- /dev/null +++ b/test/Fixture/Methods/PrivateInFinalClassRule/FinalClassImplementingAbstractProtectedMethodFromTrait.php @@ -0,0 +1,14 @@ +analyse( self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule'), [ + [ + \sprintf( + 'Method %s::method() is protected, but since the containing class is final, it can be private.', + Test\Fixture\Methods\PrivateInFinalClassRule\FinalClassImplementingAbstractProtectedMethodFromTrait::class, + ), + 11, + ], [ \sprintf( 'Method %s::method() is protected, but since the containing class is final, it can be private.', From 279ab98dbd90a35eb17b643ff4269e571b9b07a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 11:52:16 +0100 Subject: [PATCH 70/93] Fix: Add test case Related to #838. --- test/Fixture/Methods/PrivateInFinalClassRule/script.php | 8 ++++++++ test/Integration/Methods/PrivateInFinalClassRuleTest.php | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/test/Fixture/Methods/PrivateInFinalClassRule/script.php b/test/Fixture/Methods/PrivateInFinalClassRule/script.php index b79506c6..7fbc388b 100644 --- a/test/Fixture/Methods/PrivateInFinalClassRule/script.php +++ b/test/Fixture/Methods/PrivateInFinalClassRule/script.php @@ -9,3 +9,11 @@ protected function method(): void { } }; + +$bar = new class() { + use TraitWithAbstractProtectedMethod; + + protected function method(): void + { + } +}; diff --git a/test/Integration/Methods/PrivateInFinalClassRuleTest.php b/test/Integration/Methods/PrivateInFinalClassRuleTest.php index f5331cf8..705cd411 100644 --- a/test/Integration/Methods/PrivateInFinalClassRuleTest.php +++ b/test/Integration/Methods/PrivateInFinalClassRuleTest.php @@ -59,6 +59,10 @@ public function testPrivateInFinalClassRule(): void 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', 8, ], + [ + 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', + 16, + ], ], ); } From b77bbd206b995bece93a4a0da4ef98e3d1bd11ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 11:54:32 +0100 Subject: [PATCH 71/93] Fix: Add test case Related to #893. --- test/Fixture/Methods/PrivateInFinalClassRule/script.php | 4 ++++ test/Integration/Methods/PrivateInFinalClassRuleTest.php | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/test/Fixture/Methods/PrivateInFinalClassRule/script.php b/test/Fixture/Methods/PrivateInFinalClassRule/script.php index 7fbc388b..e124f036 100644 --- a/test/Fixture/Methods/PrivateInFinalClassRule/script.php +++ b/test/Fixture/Methods/PrivateInFinalClassRule/script.php @@ -11,6 +11,10 @@ protected function method(): void }; $bar = new class() { + use TraitWithProtectedMethod; +}; + +$baz = new class() { use TraitWithAbstractProtectedMethod; protected function method(): void diff --git a/test/Integration/Methods/PrivateInFinalClassRuleTest.php b/test/Integration/Methods/PrivateInFinalClassRuleTest.php index 705cd411..a7fd147a 100644 --- a/test/Integration/Methods/PrivateInFinalClassRuleTest.php +++ b/test/Integration/Methods/PrivateInFinalClassRuleTest.php @@ -61,7 +61,11 @@ public function testPrivateInFinalClassRule(): void ], [ 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', - 16, + 9, + ], + [ + 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', + 20, ], ], ); From 8f69c05c0e68df48acd4a3ed8f1b5b7c221d7926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 12:09:42 +0100 Subject: [PATCH 72/93] Fix: Wrapping --- src/Classes/FinalRule.php | 5 ++++- src/Methods/PrivateInFinalClassRule.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Classes/FinalRule.php b/src/Classes/FinalRule.php index 63b1aec8..7ad88a22 100644 --- a/src/Classes/FinalRule.php +++ b/src/Classes/FinalRule.php @@ -81,7 +81,10 @@ public function processNode( return []; } - if ($this->allowAbstractClasses && $node->isAbstract()) { + if ( + $this->allowAbstractClasses + && $node->isAbstract() + ) { return []; } diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index ec1f5062..9187ee82 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -52,7 +52,10 @@ public function processNode( $parentClass = $containingClass->getNativeReflection()->getParentClass(); - if ($parentClass instanceof \ReflectionClass && $parentClass->hasMethod($methodName)) { + if ( + $parentClass instanceof \ReflectionClass + && $parentClass->hasMethod($methodName) + ) { $parentMethod = $parentClass->getMethod($methodName); if ($parentMethod->isProtected()) { From 2193f1434ed85e8d10f2517e421b260e31b9201a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 12:13:07 +0100 Subject: [PATCH 73/93] Fix: Add test case Related to #893. --- ...inalClassOverridingProtectedMethodFromTrait.php | 14 ++++++++++++++ .../Methods/PrivateInFinalClassRuleTest.php | 7 +++++++ 2 files changed, 21 insertions(+) create mode 100644 test/Fixture/Methods/PrivateInFinalClassRule/FinalClassOverridingProtectedMethodFromTrait.php diff --git a/test/Fixture/Methods/PrivateInFinalClassRule/FinalClassOverridingProtectedMethodFromTrait.php b/test/Fixture/Methods/PrivateInFinalClassRule/FinalClassOverridingProtectedMethodFromTrait.php new file mode 100644 index 00000000..53d208d5 --- /dev/null +++ b/test/Fixture/Methods/PrivateInFinalClassRule/FinalClassOverridingProtectedMethodFromTrait.php @@ -0,0 +1,14 @@ + Date: Mon, 6 Jan 2025 12:15:13 +0100 Subject: [PATCH 74/93] Fix: Add test case Related to #893. --- test/Fixture/Methods/PrivateInFinalClassRule/script.php | 8 ++++++++ test/Integration/Methods/PrivateInFinalClassRuleTest.php | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/test/Fixture/Methods/PrivateInFinalClassRule/script.php b/test/Fixture/Methods/PrivateInFinalClassRule/script.php index e124f036..64527562 100644 --- a/test/Fixture/Methods/PrivateInFinalClassRule/script.php +++ b/test/Fixture/Methods/PrivateInFinalClassRule/script.php @@ -15,6 +15,14 @@ protected function method(): void }; $baz = new class() { + use TraitWithProtectedMethod; + + protected function method(): void + { + } +}; + +$qux = new class() { use TraitWithAbstractProtectedMethod; protected function method(): void diff --git a/test/Integration/Methods/PrivateInFinalClassRuleTest.php b/test/Integration/Methods/PrivateInFinalClassRuleTest.php index 63e4639c..535ff484 100644 --- a/test/Integration/Methods/PrivateInFinalClassRuleTest.php +++ b/test/Integration/Methods/PrivateInFinalClassRuleTest.php @@ -74,6 +74,10 @@ public function testPrivateInFinalClassRule(): void 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', 20, ], + [ + 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', + 28, + ], ], ); } From 56fe98717765bc1f2ebeb6fed56a4f5b050b0ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 12:27:11 +0100 Subject: [PATCH 75/93] Enhancement: Extract method --- src/Methods/PrivateInFinalClassRule.php | 30 ++++++++++++++++--------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index 9187ee82..37e01d15 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -50,17 +50,8 @@ public function processNode( $methodName = $node->name->toString(); - $parentClass = $containingClass->getNativeReflection()->getParentClass(); - - if ( - $parentClass instanceof \ReflectionClass - && $parentClass->hasMethod($methodName) - ) { - $parentMethod = $parentClass->getMethod($methodName); - - if ($parentMethod->isProtected()) { - return []; - } + if (self::methodIsDeclaredByParentClass($containingClass, $methodName)) { + return []; } /** @var Reflection\ClassReflection $classReflection */ @@ -91,4 +82,21 @@ public function processNode( ->build(), ]; } + + private static function methodIsDeclaredByParentClass( + Reflection\ClassReflection $containingClass, + string $methodName + ): bool { + $parentClass = $containingClass->getNativeReflection()->getParentClass(); + + if (!$parentClass instanceof \ReflectionClass) { + return false; + } + + if (!$parentClass->hasMethod($methodName)) { + return false; + } + + return true; + } } From e5bd8b56056c9bee7d86d12b022eafd4ca33baf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 12:33:21 +0100 Subject: [PATCH 76/93] Fix: Typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b461c757..ccfaaa7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ For a full diff see [`2.5.0...main`][2.5.0...main]. - Returned rule with error identifier ([#882]), by [@localheinz] - Adjusted `Methods\FinalInAbstractClassRule` to ignore Doctrine embeddables and entities ([#396]), by [@localheinz] - Adjusted `Expressions\NoCompactRule` to detect usages of `compact()` with incorrect case ([#889]), by [@localheinz] -- Adjusted `Methods\PrivateInFinalClass` to use more appropriate message when detecting a `proected` method in an anonymous class ([#890]), by [@localheinz] +- Adjusted `Methods\PrivateInFinalClass` to use more appropriate message when detecting a `protected` method in an anonymous class ([#890]), by [@localheinz] ## [`2.5.0`][2.5.0] From 30998b6800f6795c9fd530549182640a31ec6526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 6 Jan 2025 12:34:26 +0100 Subject: [PATCH 77/93] Fix: Ignore protected methods declared in traits --- CHANGELOG.md | 2 ++ src/Methods/PrivateInFinalClassRule.php | 17 ++++++++++ .../Methods/PrivateInFinalClassRuleTest.php | 33 ------------------- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccfaaa7a..fae4f281 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ For a full diff see [`2.5.0...main`][2.5.0...main]. - Adjusted `Methods\FinalInAbstractClassRule` to ignore Doctrine embeddables and entities ([#396]), by [@localheinz] - Adjusted `Expressions\NoCompactRule` to detect usages of `compact()` with incorrect case ([#889]), by [@localheinz] - Adjusted `Methods\PrivateInFinalClass` to use more appropriate message when detecting a `protected` method in an anonymous class ([#890]), by [@localheinz] +- Adjusted `Methods\PrivateInFinalClass` to ignore `protected` methods from traits([#891]), by [@localheinz] ## [`2.5.0`][2.5.0] @@ -554,6 +555,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [#882]: https://github.com/ergebnis/phpstan-rules/pull/882 [#889]: https://github.com/ergebnis/phpstan-rules/pull/889 [#890]: https://github.com/ergebnis/phpstan-rules/pull/890 +[#891]: https://github.com/ergebnis/phpstan-rules/pull/891 [@enumag]: https://github.com/enumag [@ergebnis]: https://github.com/ergebnis diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index 37e01d15..484089fc 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -54,6 +54,10 @@ public function processNode( return []; } + if (self::methodIsDeclaredByTrait($containingClass, $methodName)) { + return []; + } + /** @var Reflection\ClassReflection $classReflection */ $classReflection = $scope->getClassReflection(); @@ -99,4 +103,17 @@ private static function methodIsDeclaredByParentClass( return true; } + + private static function methodIsDeclaredByTrait( + Reflection\ClassReflection $containingClass, + string $methodName + ): bool { + foreach ($containingClass->getTraits() as $trait) { + if ($trait->hasMethod($methodName)) { + return true; + } + } + + return false; + } } diff --git a/test/Integration/Methods/PrivateInFinalClassRuleTest.php b/test/Integration/Methods/PrivateInFinalClassRuleTest.php index 535ff484..0903c370 100644 --- a/test/Integration/Methods/PrivateInFinalClassRuleTest.php +++ b/test/Integration/Methods/PrivateInFinalClassRuleTest.php @@ -34,20 +34,6 @@ public function testPrivateInFinalClassRule(): void $this->analyse( self::phpFilesIn(__DIR__ . '/../../Fixture/Methods/PrivateInFinalClassRule'), [ - [ - \sprintf( - 'Method %s::method() is protected, but since the containing class is final, it can be private.', - Test\Fixture\Methods\PrivateInFinalClassRule\FinalClassImplementingAbstractProtectedMethodFromTrait::class, - ), - 11, - ], - [ - \sprintf( - 'Method %s::method() is protected, but since the containing class is final, it can be private.', - Test\Fixture\Methods\PrivateInFinalClassRule\FinalClassOverridingProtectedMethodFromTrait::class, - ), - 11, - ], [ \sprintf( 'Method %s::method() is protected, but since the containing class is final, it can be private.', @@ -55,29 +41,10 @@ public function testPrivateInFinalClassRule(): void ), 9, ], - [ - \sprintf( - 'Method %s::method() is protected, but since the containing class is final, it can be private.', - Test\Fixture\Methods\PrivateInFinalClassRule\FinalClassWithProtectedMethodFromTrait::class, - ), - 9, - ], [ 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', 8, ], - [ - 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', - 9, - ], - [ - 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', - 20, - ], - [ - 'Method method() in anonymous class is protected, but since the containing class is final, it can be private.', - 28, - ], ], ); } From a95714da2f713243cba2001702c2f2d952da8175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 7 Jan 2025 13:49:13 +0100 Subject: [PATCH 78/93] Fix: Whitespace --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fae4f281..601868f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ For a full diff see [`2.5.0...main`][2.5.0...main]. - Adjusted `Methods\FinalInAbstractClassRule` to ignore Doctrine embeddables and entities ([#396]), by [@localheinz] - Adjusted `Expressions\NoCompactRule` to detect usages of `compact()` with incorrect case ([#889]), by [@localheinz] - Adjusted `Methods\PrivateInFinalClass` to use more appropriate message when detecting a `protected` method in an anonymous class ([#890]), by [@localheinz] -- Adjusted `Methods\PrivateInFinalClass` to ignore `protected` methods from traits([#891]), by [@localheinz] +- Adjusted `Methods\PrivateInFinalClass` to ignore `protected` methods from traits ([#891]), by [@localheinz] ## [`2.5.0`][2.5.0] From efbc9f84295156ddaffcc4e29d2714d4d573cd34 Mon Sep 17 00:00:00 2001 From: Luke Kuzmish <42181698+cosmastech@users.noreply.github.com> Date: Sun, 17 Nov 2024 08:23:27 -0500 Subject: [PATCH 79/93] do not throw error is method is marked as #[Before] --- composer-require-checker.json | 4 +++ phpstan-baseline.neon | 20 +++++++++++++ src/Methods/PrivateInFinalClassRule.php | 25 ++++++++++++++++ ...hProtectedMethodsWithPhpUnitAttributes.php | 30 +++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 test/Fixture/Methods/PrivateInFinalClassRule/FinalClassWithProtectedMethodsWithPhpUnitAttributes.php diff --git a/composer-require-checker.json b/composer-require-checker.json index 0dc15360..c1fa2577 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -33,6 +33,10 @@ "PHPStan\\Rules\\Rule", "PHPStan\\Rules\\RuleError", "PHPStan\\Rules\\RuleErrorBuilder", + "PHPUnit\\Framework\\Attributes\\After", + "PHPUnit\\Framework\\Attributes\\Before", + "PHPUnit\\Framework\\Attributes\\PostCondition", + "PHPUnit\\Framework\\Attributes\\PreCondition", "self", "string", "true" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e2e011fd..ac0ddfff 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -20,3 +20,23 @@ parameters: count: 1 path: src/Functions/NoNullableReturnTypeDeclarationRule.php + - + message: "#^Class PHPUnit\\\\Framework\\\\Attributes\\\\After not found\\.$#" + count: 1 + path: src/Methods/PrivateInFinalClassRule.php + + - + message: "#^Class PHPUnit\\\\Framework\\\\Attributes\\\\Before not found\\.$#" + count: 1 + path: src/Methods/PrivateInFinalClassRule.php + + - + message: "#^Class PHPUnit\\\\Framework\\\\Attributes\\\\PostCondition not found\\.$#" + count: 1 + path: src/Methods/PrivateInFinalClassRule.php + + - + message: "#^Class PHPUnit\\\\Framework\\\\Attributes\\\\PreCondition not found\\.$#" + count: 1 + path: src/Methods/PrivateInFinalClassRule.php + diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index 484089fc..d7c01c6f 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -18,6 +18,7 @@ use PHPStan\Analyser; use PHPStan\Reflection; use PHPStan\Rules; +use PHPUnit\Framework; /** * @implements Rules\Rule @@ -48,6 +49,10 @@ public function processNode( return []; } + if (self::methodHasPhpUnitAttributeWhichRequiresProtectedVisibility($node)) { + return []; + } + $methodName = $node->name->toString(); if (self::methodIsDeclaredByParentClass($containingClass, $methodName)) { @@ -87,6 +92,26 @@ public function processNode( ]; } + private static function methodHasPhpUnitAttributeWhichRequiresProtectedVisibility(Node\Stmt\ClassMethod $node): bool + { + $attributes = [ + Framework\Attributes\Before::class, + Framework\Attributes\After::class, + Framework\Attributes\PostCondition::class, + Framework\Attributes\PreCondition::class, + ]; + + foreach ($node->attrGroups as $attrGroup) { + foreach ($attrGroup->attrs as $attribute) { + if (\in_array($attribute->name->toString(), $attributes, true)) { + return true; + } + } + } + + return false; + } + private static function methodIsDeclaredByParentClass( Reflection\ClassReflection $containingClass, string $methodName diff --git a/test/Fixture/Methods/PrivateInFinalClassRule/FinalClassWithProtectedMethodsWithPhpUnitAttributes.php b/test/Fixture/Methods/PrivateInFinalClassRule/FinalClassWithProtectedMethodsWithPhpUnitAttributes.php new file mode 100644 index 00000000..9acd987c --- /dev/null +++ b/test/Fixture/Methods/PrivateInFinalClassRule/FinalClassWithProtectedMethodsWithPhpUnitAttributes.php @@ -0,0 +1,30 @@ + Date: Tue, 7 Jan 2025 16:31:30 +0100 Subject: [PATCH 80/93] Fix: Order --- src/Methods/PrivateInFinalClassRule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index d7c01c6f..c63329e8 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -95,8 +95,8 @@ public function processNode( private static function methodHasPhpUnitAttributeWhichRequiresProtectedVisibility(Node\Stmt\ClassMethod $node): bool { $attributes = [ - Framework\Attributes\Before::class, Framework\Attributes\After::class, + Framework\Attributes\Before::class, Framework\Attributes\PostCondition::class, Framework\Attributes\PreCondition::class, ]; From c8798402fd48665acf4f562552a731c9739a9625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 7 Jan 2025 16:47:06 +0100 Subject: [PATCH 81/93] Fix: Add pull request to CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 601868f2..770f733f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ For a full diff see [`2.5.0...main`][2.5.0...main]. - Adjusted `Expressions\NoCompactRule` to detect usages of `compact()` with incorrect case ([#889]), by [@localheinz] - Adjusted `Methods\PrivateInFinalClass` to use more appropriate message when detecting a `protected` method in an anonymous class ([#890]), by [@localheinz] - Adjusted `Methods\PrivateInFinalClass` to ignore `protected` methods from traits ([#891]), by [@localheinz] +- Adjusted `Methods\PrivateInFinalClass` to ignore `protected` methods with `phpunit/phpunit` attributes requiring methods to be `protected` ([#863]), by [@cosmastech] ## [`2.5.0`][2.5.0] @@ -547,6 +548,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [#567]: https://github.com/ergebnis/phpstan-rules/pull/567 [#735]: https://github.com/ergebnis/phpstan-rules/pull/735 [#862]: https://github.com/ergebnis/phpstan-rules/pull/862 +[#863]: https://github.com/ergebnis/phpstan-rules/pull/863 [#872]: https://github.com/ergebnis/phpstan-rules/pull/872 [#875]: https://github.com/ergebnis/phpstan-rules/pull/875 [#877]: https://github.com/ergebnis/phpstan-rules/pull/877 @@ -558,6 +560,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [#891]: https://github.com/ergebnis/phpstan-rules/pull/891 [@enumag]: https://github.com/enumag +[@cosmastech]: https://github.com/cosmastech [@ergebnis]: https://github.com/ergebnis [@Great-Antique]: https://github.com/Great-Antique [@localheinz]: https://github.com/localheinz From 117fe5175c862f364416145e891df7bf02bfc25d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 7 Jan 2025 16:47:47 +0100 Subject: [PATCH 82/93] Fix: Name --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 770f733f..b75b3e17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,9 +13,9 @@ For a full diff see [`2.5.0...main`][2.5.0...main]. - Returned rule with error identifier ([#882]), by [@localheinz] - Adjusted `Methods\FinalInAbstractClassRule` to ignore Doctrine embeddables and entities ([#396]), by [@localheinz] - Adjusted `Expressions\NoCompactRule` to detect usages of `compact()` with incorrect case ([#889]), by [@localheinz] -- Adjusted `Methods\PrivateInFinalClass` to use more appropriate message when detecting a `protected` method in an anonymous class ([#890]), by [@localheinz] -- Adjusted `Methods\PrivateInFinalClass` to ignore `protected` methods from traits ([#891]), by [@localheinz] -- Adjusted `Methods\PrivateInFinalClass` to ignore `protected` methods with `phpunit/phpunit` attributes requiring methods to be `protected` ([#863]), by [@cosmastech] +- Adjusted `Methods\PrivateInFinalClassRule` to use more appropriate message when detecting a `protected` method in an anonymous class ([#890]), by [@localheinz] +- Adjusted `Methods\PrivateInFinalClassRule` to ignore `protected` methods from traits ([#891]), by [@localheinz] +- Adjusted `Methods\PrivateInFinalClassRule` to ignore `protected` methods with `phpunit/phpunit` attributes requiring methods to be `protected` ([#863]), by [@cosmastech] ## [`2.5.0`][2.5.0] From 778beac8eb9ff95025079ebf1d67464bfd538024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 7 Jan 2025 16:50:39 +0100 Subject: [PATCH 83/93] Fix: Do not require methods with phpunit/phpunit annotations to be private --- CHANGELOG.md | 2 + composer-require-checker.json | 1 + src/Methods/PrivateInFinalClassRule.php | 49 +++++++++++++++++++ ...ProtectedMethodsWithPhpUnitAnnotations.php | 38 ++++++++++++++ .../Methods/PrivateInFinalClassRuleTest.php | 5 +- 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 test/Fixture/Methods/PrivateInFinalClassRule/FinalClassWithProtectedMethodsWithPhpUnitAnnotations.php diff --git a/CHANGELOG.md b/CHANGELOG.md index b75b3e17..342b86e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ For a full diff see [`2.5.0...main`][2.5.0...main]. - Adjusted `Methods\PrivateInFinalClassRule` to use more appropriate message when detecting a `protected` method in an anonymous class ([#890]), by [@localheinz] - Adjusted `Methods\PrivateInFinalClassRule` to ignore `protected` methods from traits ([#891]), by [@localheinz] - Adjusted `Methods\PrivateInFinalClassRule` to ignore `protected` methods with `phpunit/phpunit` attributes requiring methods to be `protected` ([#863]), by [@cosmastech] +- Adjusted `Methods\PrivateInFinalClassRule` to ignore `protected` methods with `phpunit/phpunit` annotations requiring methods to be `protected` ([#895]), by [@cosmastech] ## [`2.5.0`][2.5.0] @@ -558,6 +559,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [#889]: https://github.com/ergebnis/phpstan-rules/pull/889 [#890]: https://github.com/ergebnis/phpstan-rules/pull/890 [#891]: https://github.com/ergebnis/phpstan-rules/pull/891 +[#895]: https://github.com/ergebnis/phpstan-rules/pull/895 [@enumag]: https://github.com/enumag [@cosmastech]: https://github.com/cosmastech diff --git a/composer-require-checker.json b/composer-require-checker.json index c1fa2577..dbbbecfd 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -33,6 +33,7 @@ "PHPStan\\Rules\\Rule", "PHPStan\\Rules\\RuleError", "PHPStan\\Rules\\RuleErrorBuilder", + "PHPStan\\Type\\FileTypeMapper", "PHPUnit\\Framework\\Attributes\\After", "PHPUnit\\Framework\\Attributes\\Before", "PHPUnit\\Framework\\Attributes\\PostCondition", diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index c63329e8..8f574265 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -14,10 +14,12 @@ namespace Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\ErrorIdentifier; +use PhpParser\Comment; use PhpParser\Node; use PHPStan\Analyser; use PHPStan\Reflection; use PHPStan\Rules; +use PHPStan\Type; use PHPUnit\Framework; /** @@ -25,6 +27,13 @@ */ final class PrivateInFinalClassRule implements Rules\Rule { + private Type\FileTypeMapper $fileTypeMapper; + + public function __construct(Type\FileTypeMapper $fileTypeMapper) + { + $this->fileTypeMapper = $fileTypeMapper; + } + public function getNodeType(): string { return Node\Stmt\ClassMethod::class; @@ -49,6 +58,10 @@ public function processNode( return []; } + if ($this->methodHasPhpUnitAnnotationWhichRequiresProtectedVisibility($node, $containingClass)) { + return []; + } + if (self::methodHasPhpUnitAttributeWhichRequiresProtectedVisibility($node)) { return []; } @@ -92,6 +105,42 @@ public function processNode( ]; } + private function methodHasPhpUnitAnnotationWhichRequiresProtectedVisibility( + Node\Stmt\ClassMethod $node, + Reflection\ClassReflection $containingClass + ): bool { + $docComment = $node->getDocComment(); + + if (!$docComment instanceof Comment\Doc) { + return false; + } + + $resolvedPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc( + null, + $containingClass->getName(), + null, + null, + $docComment->getText(), + ); + + $annotations = [ + '@after', + '@before', + '@postCondition', + '@preCondition', + ]; + + foreach ($resolvedPhpDoc->getPhpDocNodes() as $phpDocNode) { + foreach ($phpDocNode->getTags() as $tag) { + if (\in_array($tag->name, $annotations, true)) { + return true; + } + } + } + + return false; + } + private static function methodHasPhpUnitAttributeWhichRequiresProtectedVisibility(Node\Stmt\ClassMethod $node): bool { $attributes = [ diff --git a/test/Fixture/Methods/PrivateInFinalClassRule/FinalClassWithProtectedMethodsWithPhpUnitAnnotations.php b/test/Fixture/Methods/PrivateInFinalClassRule/FinalClassWithProtectedMethodsWithPhpUnitAnnotations.php new file mode 100644 index 00000000..deb1ae93 --- /dev/null +++ b/test/Fixture/Methods/PrivateInFinalClassRule/FinalClassWithProtectedMethodsWithPhpUnitAnnotations.php @@ -0,0 +1,38 @@ +getByType(Type\FileTypeMapper::class); + + return new Methods\PrivateInFinalClassRule($fileTypeMapper); } } From 9999fb11a1c426d616a10f6ee7c524b9d7bd2e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 7 Jan 2025 17:43:59 +0100 Subject: [PATCH 84/93] Enhancement: Prepare release --- .github/SECURITY.md | 4 ++-- CHANGELOG.md | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/SECURITY.md b/.github/SECURITY.md index f9ca5b42..4fb2044f 100644 --- a/.github/SECURITY.md +++ b/.github/SECURITY.md @@ -4,13 +4,13 @@ The following versions of `ergebnis/phpstan-rules` have active support: -- `^2.5.0` +- `^2.5.1` ## Unsupported Versions The following versions of `ergebnis/phpstan-rules` have reached their end of life: -- `<2.5.0` +- `<2.5.1` ## Reporting a Vulnerability diff --git a/CHANGELOG.md b/CHANGELOG.md index 342b86e3..8e705b8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased -For a full diff see [`2.5.0...main`][2.5.0...main]. +For a full diff see [`2.5.1...main`][2.5.1...main]. + +## [`2.5.1`][2.5.1] + +For a full diff see [`2.5.0...2.5.1`][2.5.0...2.5.1]. ### Fixed @@ -447,6 +451,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [2.3.0]: https://github.com/ergebnis/phpstan-rules/releases/tag/2.3.0 [2.4.0]: https://github.com/ergebnis/phpstan-rules/releases/tag/2.4.0 [2.5.0]: https://github.com/ergebnis/phpstan-rules/releases/tag/2.5.0 +[2.5.1]: https://github.com/ergebnis/phpstan-rules/releases/tag/2.5.1 [362c7ea...0.1.0]: https://github.com/ergebnis/phpstan-rules/compare/362c7ea...0.1.0 [0.1.0...0.2.0]: https://github.com/ergebnis/phpstan-rules/compare/0.1.0...0.2.0 @@ -482,7 +487,8 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [2.2.0...2.3.0]: https://github.com/ergebnis/phpstan-rules/compare/2.2.0...2.3.0 [2.3.0...2.4.0]: https://github.com/ergebnis/phpstan-rules/compare/2.3.0...2.4.0 [2.4.0...2.5.0]: https://github.com/ergebnis/phpstan-rules/compare/2.4.0...2.5.0 -[2.5.0...main]: https://github.com/ergebnis/phpstan-rules/compare/2.5.0...main +[2.5.0...2.5.1]: https://github.com/ergebnis/phpstan-rules/compare/2.5.0...2.5.1 +[2.5.1...main]: https://github.com/ergebnis/phpstan-rules/compare/2.5.1...main [#1]: https://github.com/ergebnis/phpstan-rules/pull/1 [#4]: https://github.com/ergebnis/phpstan-rules/pull/4 From 26ec39c874bc78c3ff0b7ca6663d2f1e33141653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 7 Jan 2025 19:36:05 +0100 Subject: [PATCH 85/93] Fix: Rename variable --- src/Methods/PrivateInFinalClassRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index 8f574265..25e4af8d 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -150,8 +150,8 @@ private static function methodHasPhpUnitAttributeWhichRequiresProtectedVisibilit Framework\Attributes\PreCondition::class, ]; - foreach ($node->attrGroups as $attrGroup) { - foreach ($attrGroup->attrs as $attribute) { + foreach ($node->attrGroups as $attributeGroup) { + foreach ($attributeGroup->attrs as $attribute) { if (\in_array($attribute->name->toString(), $attributes, true)) { return true; } From 44c7c4d51b8c47ae920327e451909b39b1b8c302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 7 Jan 2025 19:38:16 +0100 Subject: [PATCH 86/93] Fix: Use ::class pseudo-constant --- composer-require-checker.json | 1 + src/Classes/FinalRule.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/composer-require-checker.json b/composer-require-checker.json index dbbbecfd..92f8a316 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -2,6 +2,7 @@ "symbol-whitelist": [ "array", "bool", + "Doctrine\\ORM\\Mapping\\Entity", "false", "null", "PhpParser\\Comment\\Doc", diff --git a/src/Classes/FinalRule.php b/src/Classes/FinalRule.php index 7ad88a22..b1d0df43 100644 --- a/src/Classes/FinalRule.php +++ b/src/Classes/FinalRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Classes; +use Doctrine\ORM; use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Comment; use PhpParser\Node; @@ -37,7 +38,7 @@ final class FinalRule implements Rules\Rule * @var list */ private static array $whitelistedAttributes = [ - 'Doctrine\ORM\Mapping\Entity', + ORM\Mapping\Entity::class, ]; private bool $allowAbstractClasses; From 6de6bb37efe43dd587bff802be6ff52c36842ad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 7 Jan 2025 19:41:17 +0100 Subject: [PATCH 87/93] Fix: Rename methods and extract fields --- src/Methods/PrivateInFinalClassRule.php | 45 ++++++++++++++----------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index 25e4af8d..1e91d37a 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -27,6 +27,25 @@ */ final class PrivateInFinalClassRule implements Rules\Rule { + /** + * @var list + */ + private static array $whitelistedAnnotations = [ + '@after', + '@before', + '@postCondition', + '@preCondition', + ]; + + /** + * @var list + */ + private static array $whitelistedAttributes = [ + Framework\Attributes\After::class, + Framework\Attributes\Before::class, + Framework\Attributes\PostCondition::class, + Framework\Attributes\PreCondition::class, + ]; private Type\FileTypeMapper $fileTypeMapper; public function __construct(Type\FileTypeMapper $fileTypeMapper) @@ -58,11 +77,11 @@ public function processNode( return []; } - if ($this->methodHasPhpUnitAnnotationWhichRequiresProtectedVisibility($node, $containingClass)) { + if ($this->methodHasWhitelistedAnnotation($node, $containingClass)) { return []; } - if (self::methodHasPhpUnitAttributeWhichRequiresProtectedVisibility($node)) { + if (self::methodHasWhitelistedAttribute($node)) { return []; } @@ -105,7 +124,7 @@ public function processNode( ]; } - private function methodHasPhpUnitAnnotationWhichRequiresProtectedVisibility( + private function methodHasWhitelistedAnnotation( Node\Stmt\ClassMethod $node, Reflection\ClassReflection $containingClass ): bool { @@ -123,16 +142,9 @@ private function methodHasPhpUnitAnnotationWhichRequiresProtectedVisibility( $docComment->getText(), ); - $annotations = [ - '@after', - '@before', - '@postCondition', - '@preCondition', - ]; - foreach ($resolvedPhpDoc->getPhpDocNodes() as $phpDocNode) { foreach ($phpDocNode->getTags() as $tag) { - if (\in_array($tag->name, $annotations, true)) { + if (\in_array($tag->name, self::$whitelistedAnnotations, true)) { return true; } } @@ -141,18 +153,11 @@ private function methodHasPhpUnitAnnotationWhichRequiresProtectedVisibility( return false; } - private static function methodHasPhpUnitAttributeWhichRequiresProtectedVisibility(Node\Stmt\ClassMethod $node): bool + private static function methodHasWhitelistedAttribute(Node\Stmt\ClassMethod $node): bool { - $attributes = [ - Framework\Attributes\After::class, - Framework\Attributes\Before::class, - Framework\Attributes\PostCondition::class, - Framework\Attributes\PreCondition::class, - ]; - foreach ($node->attrGroups as $attributeGroup) { foreach ($attributeGroup->attrs as $attribute) { - if (\in_array($attribute->name->toString(), $attributes, true)) { + if (\in_array($attribute->name->toString(), self::$whitelistedAttributes, true)) { return true; } } From 7a4477619539c214ab5bc5579c0cc0f897150760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 7 Jan 2025 19:44:24 +0100 Subject: [PATCH 88/93] Fix: Rename methods --- src/Methods/PrivateInFinalClassRule.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Methods/PrivateInFinalClassRule.php b/src/Methods/PrivateInFinalClassRule.php index 1e91d37a..9aa2c3cc 100644 --- a/src/Methods/PrivateInFinalClassRule.php +++ b/src/Methods/PrivateInFinalClassRule.php @@ -77,21 +77,21 @@ public function processNode( return []; } - if ($this->methodHasWhitelistedAnnotation($node, $containingClass)) { + if ($this->hasWhitelistedAnnotation($node, $containingClass)) { return []; } - if (self::methodHasWhitelistedAttribute($node)) { + if (self::hasWhitelistedAttribute($node)) { return []; } $methodName = $node->name->toString(); - if (self::methodIsDeclaredByParentClass($containingClass, $methodName)) { + if (self::isDeclaredByParentClass($containingClass, $methodName)) { return []; } - if (self::methodIsDeclaredByTrait($containingClass, $methodName)) { + if (self::isDeclaredByTrait($containingClass, $methodName)) { return []; } @@ -124,7 +124,7 @@ public function processNode( ]; } - private function methodHasWhitelistedAnnotation( + private function hasWhitelistedAnnotation( Node\Stmt\ClassMethod $node, Reflection\ClassReflection $containingClass ): bool { @@ -153,7 +153,7 @@ private function methodHasWhitelistedAnnotation( return false; } - private static function methodHasWhitelistedAttribute(Node\Stmt\ClassMethod $node): bool + private static function hasWhitelistedAttribute(Node\Stmt\ClassMethod $node): bool { foreach ($node->attrGroups as $attributeGroup) { foreach ($attributeGroup->attrs as $attribute) { @@ -166,7 +166,7 @@ private static function methodHasWhitelistedAttribute(Node\Stmt\ClassMethod $nod return false; } - private static function methodIsDeclaredByParentClass( + private static function isDeclaredByParentClass( Reflection\ClassReflection $containingClass, string $methodName ): bool { @@ -183,7 +183,7 @@ private static function methodIsDeclaredByParentClass( return true; } - private static function methodIsDeclaredByTrait( + private static function isDeclaredByTrait( Reflection\ClassReflection $containingClass, string $methodName ): bool { From c6339368a2eaa8ef49b44c0fcc05b3a1abc87d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 7 Jan 2025 19:45:59 +0100 Subject: [PATCH 89/93] Fix: Split method --- src/Classes/FinalRule.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Classes/FinalRule.php b/src/Classes/FinalRule.php index b1d0df43..2037d663 100644 --- a/src/Classes/FinalRule.php +++ b/src/Classes/FinalRule.php @@ -93,7 +93,11 @@ public function processNode( return []; } - if ($this->isWhitelisted($node)) { + if ($this->hasWhitelistedAnnotation($node)) { + return []; + } + + if ($this->hasWhitelistedAttribute($node)) { return []; } @@ -120,16 +124,8 @@ public function processNode( * @see https://github.com/SpacePossum * @see https://github.com/Slamdunk */ - private function isWhitelisted(Node\Stmt\Class_ $node): bool + private function hasWhitelistedAnnotation(Node\Stmt\Class_ $node): bool { - foreach ($node->attrGroups as $attributeGroup) { - foreach ($attributeGroup->attrs as $attribute) { - if (\in_array($attribute->name->toString(), self::$whitelistedAttributes, true)) { - return true; - } - } - } - $docComment = $node->getDocComment(); if (!$docComment instanceof Comment\Doc) { @@ -154,4 +150,17 @@ private function isWhitelisted(Node\Stmt\Class_ $node): bool return false; } + + private function hasWhitelistedAttribute(Node\Stmt\Class_ $node): bool + { + foreach ($node->attrGroups as $attributeGroup) { + foreach ($attributeGroup->attrs as $attribute) { + if (\in_array($attribute->name->toString(), self::$whitelistedAttributes, true)) { + return true; + } + } + } + + return false; + } } From c97079d66f8db8b7e1a5b6e33efef8753a3c642d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 7 Jan 2025 23:15:29 +0100 Subject: [PATCH 90/93] Enhancement: Extract Analyzer --- rules.neon | 3 + src/Analyzer.php | 55 +++++++++++++++++++ .../NoNullableReturnTypeDeclarationRule.php | 33 +++-------- .../NoParameterWithNullDefaultValueRule.php | 21 ++++--- ...rameterWithNullableTypeDeclarationRule.php | 35 ++++-------- .../NoNullableReturnTypeDeclarationRule.php | 33 +++-------- .../NoParameterWithNullDefaultValueRule.php | 21 ++++--- ...rameterWithNullableTypeDeclarationRule.php | 35 ++++-------- .../NoNullableReturnTypeDeclarationRule.php | 33 +++-------- .../NoParameterWithNullDefaultValueRule.php | 21 ++++--- ...rameterWithNullableTypeDeclarationRule.php | 35 ++++-------- ...oNullableReturnTypeDeclarationRuleTest.php | 4 +- ...oParameterWithNullDefaultValueRuleTest.php | 4 +- ...terWithNullableTypeDeclarationRuleTest.php | 4 +- ...oNullableReturnTypeDeclarationRuleTest.php | 4 +- ...oParameterWithNullDefaultValueRuleTest.php | 4 +- ...terWithNullableTypeDeclarationRuleTest.php | 4 +- ...oNullableReturnTypeDeclarationRuleTest.php | 4 +- ...oParameterWithNullDefaultValueRuleTest.php | 4 +- ...terWithNullableTypeDeclarationRuleTest.php | 4 +- 20 files changed, 172 insertions(+), 189 deletions(-) create mode 100644 src/Analyzer.php diff --git a/rules.neon b/rules.neon index 123cc83b..7f827de8 100644 --- a/rules.neon +++ b/rules.neon @@ -141,6 +141,9 @@ parametersSchema: ]) services: + - + class: Ergebnis\PHPStan\Rules\Analyzer + - class: Ergebnis\PHPStan\Rules\Classes\FinalRule arguments: diff --git a/src/Analyzer.php b/src/Analyzer.php new file mode 100644 index 00000000..4e0a6d4a --- /dev/null +++ b/src/Analyzer.php @@ -0,0 +1,55 @@ +default instanceof Node\Expr\ConstFetch) { + return false; + } + + return 'null' === $parameter->default->name->toLowerString(); + } + + /** + * @param null|Node\ComplexType|Node\Identifier|Node\Name $typeDeclaration + */ + public function isNullableTypeDeclaration($typeDeclaration): bool + { + if ($typeDeclaration instanceof Node\NullableType) { + return true; + } + + if ($typeDeclaration instanceof Node\UnionType) { + foreach ($typeDeclaration->types as $type) { + if (!$type instanceof Node\Identifier) { + continue; + } + + if ('null' === $type->toLowerString()) { + return true; + } + } + } + + return false; + } +} diff --git a/src/Closures/NoNullableReturnTypeDeclarationRule.php b/src/Closures/NoNullableReturnTypeDeclarationRule.php index 28aef1db..64351579 100644 --- a/src/Closures/NoNullableReturnTypeDeclarationRule.php +++ b/src/Closures/NoNullableReturnTypeDeclarationRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Closures; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; @@ -23,6 +24,13 @@ */ final class NoNullableReturnTypeDeclarationRule implements Rules\Rule { + private Analyzer $analyzer; + + public function __construct(Analyzer $analyzer) + { + $this->analyzer = $analyzer; + } + public function getNodeType(): string { return Node\Expr\Closure::class; @@ -32,7 +40,7 @@ public function processNode( Node $node, Analyser\Scope $scope ): array { - if (!self::hasNullableReturnTypeDeclaration($node)) { + if (!$this->analyzer->isNullableTypeDeclaration($node->getReturnType())) { return []; } @@ -42,27 +50,4 @@ public function processNode( ->build(), ]; } - - private static function hasNullableReturnTypeDeclaration(Node\Expr\Closure $closure): bool - { - $returnType = $closure->getReturnType(); - - if ($returnType instanceof Node\NullableType) { - return true; - } - - if ($returnType instanceof Node\UnionType) { - foreach ($returnType->types as $type) { - if (!$type instanceof Node\Identifier) { - continue; - } - - if ('null' === $type->toString()) { - return true; - } - } - } - - return false; - } } diff --git a/src/Closures/NoParameterWithNullDefaultValueRule.php b/src/Closures/NoParameterWithNullDefaultValueRule.php index be414f70..94bd1463 100644 --- a/src/Closures/NoParameterWithNullDefaultValueRule.php +++ b/src/Closures/NoParameterWithNullDefaultValueRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Closures; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; @@ -23,6 +24,13 @@ */ final class NoParameterWithNullDefaultValueRule implements Rules\Rule { + private Analyzer $analyzer; + + public function __construct(Analyzer $analyzer) + { + $this->analyzer = $analyzer; + } + public function getNodeType(): string { return Node\Expr\Closure::class; @@ -36,8 +44,8 @@ public function processNode( return []; } - $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { - return self::hasNullDefaultValue($parameter); + $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, function (Node\Param $parameter): bool { + return $this->analyzer->hasNullDefaultValue($parameter); })); if (0 === \count($parametersWithNullDefaultValue)) { @@ -61,13 +69,4 @@ public function processNode( ->build(); }, $parametersWithNullDefaultValue); } - - private static function hasNullDefaultValue(Node\Param $parameter): bool - { - if (!$parameter->default instanceof Node\Expr\ConstFetch) { - return false; - } - - return 'null' === $parameter->default->name->toLowerString(); - } } diff --git a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php index 2a539da2..3cff6ee6 100644 --- a/src/Closures/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Closures/NoParameterWithNullableTypeDeclarationRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Closures; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; @@ -23,6 +24,13 @@ */ final class NoParameterWithNullableTypeDeclarationRule implements Rules\Rule { + private Analyzer $analyzer; + + public function __construct(Analyzer $analyzer) + { + $this->analyzer = $analyzer; + } + public function getNodeType(): string { return Node\Expr\Closure::class; @@ -36,8 +44,8 @@ public function processNode( return []; } - $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { - return self::hasNullableTypeDeclaration($parameter); + $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, function (Node\Param $parameter): bool { + return $this->analyzer->isNullableTypeDeclaration($parameter->type); })); if (0 === \count($parametersWithNullableTypeDeclaration)) { @@ -61,27 +69,4 @@ public function processNode( ->build(); }, $parametersWithNullableTypeDeclaration); } - - private static function hasNullableTypeDeclaration(Node\Param $parameter): bool - { - if ($parameter->type instanceof Node\NullableType) { - return true; - } - - if ($parameter->type instanceof Node\UnionType) { - foreach ($parameter->type->types as $type) { - if (!$type instanceof Node\Identifier) { - continue; - } - - if ('null' !== $type->toString()) { - continue; - } - - return true; - } - } - - return false; - } } diff --git a/src/Functions/NoNullableReturnTypeDeclarationRule.php b/src/Functions/NoNullableReturnTypeDeclarationRule.php index 9346eea7..06da4f72 100644 --- a/src/Functions/NoNullableReturnTypeDeclarationRule.php +++ b/src/Functions/NoNullableReturnTypeDeclarationRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Functions; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; @@ -23,6 +24,13 @@ */ final class NoNullableReturnTypeDeclarationRule implements Rules\Rule { + private Analyzer $analyzer; + + public function __construct(Analyzer $analyzer) + { + $this->analyzer = $analyzer; + } + public function getNodeType(): string { return Node\Stmt\Function_::class; @@ -36,7 +44,7 @@ public function processNode( return []; } - if (!self::hasNullableReturnTypeDeclaration($node)) { + if (!$this->analyzer->isNullableTypeDeclaration($node->getReturnType())) { return []; } @@ -51,27 +59,4 @@ public function processNode( ->build(), ]; } - - private static function hasNullableReturnTypeDeclaration(Node\Stmt\Function_ $function): bool - { - $returnType = $function->getReturnType(); - - if ($returnType instanceof Node\NullableType) { - return true; - } - - if ($returnType instanceof Node\UnionType) { - foreach ($returnType->types as $type) { - if (!$type instanceof Node\Identifier) { - continue; - } - - if ('null' === $type->toString()) { - return true; - } - } - } - - return false; - } } diff --git a/src/Functions/NoParameterWithNullDefaultValueRule.php b/src/Functions/NoParameterWithNullDefaultValueRule.php index 3f8b3d47..fe82a4e3 100644 --- a/src/Functions/NoParameterWithNullDefaultValueRule.php +++ b/src/Functions/NoParameterWithNullDefaultValueRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Functions; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; @@ -23,6 +24,13 @@ */ final class NoParameterWithNullDefaultValueRule implements Rules\Rule { + private Analyzer $analyzer; + + public function __construct(Analyzer $analyzer) + { + $this->analyzer = $analyzer; + } + public function getNodeType(): string { return Node\Stmt\Function_::class; @@ -36,8 +44,8 @@ public function processNode( return []; } - $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { - return self::hasNullDefaultValue($parameter); + $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, function (Node\Param $parameter): bool { + return $this->analyzer->hasNullDefaultValue($parameter); })); if (0 === \count($parametersWithNullDefaultValue)) { @@ -64,13 +72,4 @@ public function processNode( ->build(); }, $parametersWithNullDefaultValue); } - - private static function hasNullDefaultValue(Node\Param $parameter): bool - { - if (!$parameter->default instanceof Node\Expr\ConstFetch) { - return false; - } - - return 'null' === $parameter->default->name->toLowerString(); - } } diff --git a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php index 40a7025f..90275530 100644 --- a/src/Functions/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Functions/NoParameterWithNullableTypeDeclarationRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Functions; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; @@ -23,6 +24,13 @@ */ final class NoParameterWithNullableTypeDeclarationRule implements Rules\Rule { + private Analyzer $analyzer; + + public function __construct(Analyzer $analyzer) + { + $this->analyzer = $analyzer; + } + public function getNodeType(): string { return Node\Stmt\Function_::class; @@ -36,8 +44,8 @@ public function processNode( return []; } - $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { - return self::hasNullableTypeDeclaration($parameter); + $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, function (Node\Param $parameter): bool { + return $this->analyzer->isNullableTypeDeclaration($parameter->type); })); if (0 === \count($parametersWithNullableTypeDeclaration)) { @@ -64,27 +72,4 @@ public function processNode( ->build(); }, $parametersWithNullableTypeDeclaration); } - - private static function hasNullableTypeDeclaration(Node\Param $parameter): bool - { - if ($parameter->type instanceof Node\NullableType) { - return true; - } - - if ($parameter->type instanceof Node\UnionType) { - foreach ($parameter->type->types as $type) { - if (!$type instanceof Node\Identifier) { - continue; - } - - if ('null' !== $type->toString()) { - continue; - } - - return true; - } - } - - return false; - } } diff --git a/src/Methods/NoNullableReturnTypeDeclarationRule.php b/src/Methods/NoNullableReturnTypeDeclarationRule.php index 6a822670..e0e84c94 100644 --- a/src/Methods/NoNullableReturnTypeDeclarationRule.php +++ b/src/Methods/NoNullableReturnTypeDeclarationRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Methods; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; @@ -24,6 +25,13 @@ */ final class NoNullableReturnTypeDeclarationRule implements Rules\Rule { + private Analyzer $analyzer; + + public function __construct(Analyzer $analyzer) + { + $this->analyzer = $analyzer; + } + public function getNodeType(): string { return Node\Stmt\ClassMethod::class; @@ -33,7 +41,7 @@ public function processNode( Node $node, Analyser\Scope $scope ): array { - if (!self::hasNullableReturnTypeDeclaration($node)) { + if (!$this->analyzer->isNullableTypeDeclaration($node->getReturnType())) { return []; } @@ -65,27 +73,4 @@ public function processNode( ->build(), ]; } - - private static function hasNullableReturnTypeDeclaration(Node\Stmt\ClassMethod $method): bool - { - $returnType = $method->getReturnType(); - - if ($returnType instanceof Node\NullableType) { - return true; - } - - if ($returnType instanceof Node\UnionType) { - foreach ($returnType->types as $type) { - if (!$type instanceof Node\Identifier) { - continue; - } - - if ('null' === $type->toString()) { - return true; - } - } - } - - return false; - } } diff --git a/src/Methods/NoParameterWithNullDefaultValueRule.php b/src/Methods/NoParameterWithNullDefaultValueRule.php index 0e93f1e5..9888974c 100644 --- a/src/Methods/NoParameterWithNullDefaultValueRule.php +++ b/src/Methods/NoParameterWithNullDefaultValueRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Methods; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; @@ -24,6 +25,13 @@ */ final class NoParameterWithNullDefaultValueRule implements Rules\Rule { + private Analyzer $analyzer; + + public function __construct(Analyzer $analyzer) + { + $this->analyzer = $analyzer; + } + public function getNodeType(): string { return Node\Stmt\ClassMethod::class; @@ -37,8 +45,8 @@ public function processNode( return []; } - $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { - return self::hasNullDefaultValue($parameter); + $parametersWithNullDefaultValue = \array_values(\array_filter($node->params, function (Node\Param $parameter): bool { + return $this->analyzer->hasNullDefaultValue($parameter); })); if (0 === \count($parametersWithNullDefaultValue)) { @@ -91,13 +99,4 @@ public function processNode( ->build(); }, $parametersWithNullDefaultValue); } - - private static function hasNullDefaultValue(Node\Param $parameter): bool - { - if (!$parameter->default instanceof Node\Expr\ConstFetch) { - return false; - } - - return 'null' === $parameter->default->name->toLowerString(); - } } diff --git a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php index e06fd0fb..fdf5c5cb 100644 --- a/src/Methods/NoParameterWithNullableTypeDeclarationRule.php +++ b/src/Methods/NoParameterWithNullableTypeDeclarationRule.php @@ -13,6 +13,7 @@ namespace Ergebnis\PHPStan\Rules\Methods; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\ErrorIdentifier; use PhpParser\Node; use PHPStan\Analyser; @@ -24,6 +25,13 @@ */ final class NoParameterWithNullableTypeDeclarationRule implements Rules\Rule { + private Analyzer $analyzer; + + public function __construct(Analyzer $analyzer) + { + $this->analyzer = $analyzer; + } + public function getNodeType(): string { return Node\Stmt\ClassMethod::class; @@ -37,8 +45,8 @@ public function processNode( return []; } - $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, static function (Node\Param $parameter): bool { - return self::hasNullableTypeDeclaration($parameter); + $parametersWithNullableTypeDeclaration = \array_values(\array_filter($node->params, function (Node\Param $parameter): bool { + return $this->analyzer->isNullableTypeDeclaration($parameter->type); })); if (0 === \count($parametersWithNullableTypeDeclaration)) { @@ -91,27 +99,4 @@ public function processNode( ->build(); }, $parametersWithNullableTypeDeclaration); } - - private static function hasNullableTypeDeclaration(Node\Param $parameter): bool - { - if ($parameter->type instanceof Node\NullableType) { - return true; - } - - if ($parameter->type instanceof Node\UnionType) { - foreach ($parameter->type->types as $type) { - if (!$type instanceof Node\Identifier) { - continue; - } - - if ('null' !== $type->toString()) { - continue; - } - - return true; - } - } - - return false; - } } diff --git a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php index a2e61cc9..3bb4a879 100644 --- a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php @@ -13,12 +13,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Closures; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\Closures; use Ergebnis\PHPStan\Rules\Test; use PHPStan\Rules; use PHPStan\Testing; /** + * @covers \Ergebnis\PHPStan\Rules\Analyzer * @covers \Ergebnis\PHPStan\Rules\Closures\NoNullableReturnTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier @@ -48,6 +50,6 @@ public function testNoNullableReturnTypeDeclarationRule(): void protected function getRule(): Rules\Rule { - return new Closures\NoNullableReturnTypeDeclarationRule(); + return new Closures\NoNullableReturnTypeDeclarationRule(new Analyzer()); } } diff --git a/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php index 9b3d4847..8422e47f 100644 --- a/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Closures/NoParameterWithNullDefaultValueRuleTest.php @@ -13,12 +13,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Closures; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\Closures; use Ergebnis\PHPStan\Rules\Test; use PHPStan\Rules; use PHPStan\Testing; /** + * @covers \Ergebnis\PHPStan\Rules\Analyzer * @covers \Ergebnis\PHPStan\Rules\Closures\NoParameterWithNullDefaultValueRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier @@ -52,6 +54,6 @@ public function testNoParameterWithNullDefaultValueRule(): void protected function getRule(): Rules\Rule { - return new Closures\NoParameterWithNullDefaultValueRule(); + return new Closures\NoParameterWithNullDefaultValueRule(new Analyzer()); } } diff --git a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php index 5e6f09dc..52f8e04d 100644 --- a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -13,12 +13,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Closures; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\Closures; use Ergebnis\PHPStan\Rules\Test; use PHPStan\Rules; use PHPStan\Testing; /** + * @covers \Ergebnis\PHPStan\Rules\Analyzer * @covers \Ergebnis\PHPStan\Rules\Closures\NoParameterWithNullableTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier @@ -48,6 +50,6 @@ public function testNoParameterWithNullableTypeDeclarationRule(): void protected function getRule(): Rules\Rule { - return new Closures\NoParameterWithNullableTypeDeclarationRule(); + return new Closures\NoParameterWithNullableTypeDeclarationRule(new Analyzer()); } } diff --git a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php index c1d94b7e..ee88039e 100644 --- a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php @@ -13,12 +13,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Functions; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\Functions; use Ergebnis\PHPStan\Rules\Test; use PHPStan\Rules; use PHPStan\Testing; /** + * @covers \Ergebnis\PHPStan\Rules\Analyzer * @covers \Ergebnis\PHPStan\Rules\Functions\NoNullableReturnTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier @@ -48,6 +50,6 @@ public function testNoNullableReturnTypeDeclarationRule(): void protected function getRule(): Rules\Rule { - return new Functions\NoNullableReturnTypeDeclarationRule(); + return new Functions\NoNullableReturnTypeDeclarationRule(new Analyzer()); } } diff --git a/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php index 62753184..81e6b45a 100644 --- a/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Functions/NoParameterWithNullDefaultValueRuleTest.php @@ -13,12 +13,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Functions; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\Functions; use Ergebnis\PHPStan\Rules\Test; use PHPStan\Rules; use PHPStan\Testing; /** + * @covers \Ergebnis\PHPStan\Rules\Analyzer * @covers \Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullDefaultValueRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier @@ -52,6 +54,6 @@ public function testNoParameterWithNullDefaultValueRule(): void protected function getRule(): Rules\Rule { - return new Functions\NoParameterWithNullDefaultValueRule(); + return new Functions\NoParameterWithNullDefaultValueRule(new Analyzer()); } } diff --git a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php index 031ab514..380eefe4 100644 --- a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -13,12 +13,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Functions; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\Functions; use Ergebnis\PHPStan\Rules\Test; use PHPStan\Rules; use PHPStan\Testing; /** + * @covers \Ergebnis\PHPStan\Rules\Analyzer * @covers \Ergebnis\PHPStan\Rules\Functions\NoParameterWithNullableTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier @@ -48,6 +50,6 @@ public function testNoParameterWithNullableTypeDeclarationRule(): void protected function getRule(): Rules\Rule { - return new Functions\NoParameterWithNullableTypeDeclarationRule(); + return new Functions\NoParameterWithNullableTypeDeclarationRule(new Analyzer()); } } diff --git a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php index a565a4b7..d0cad8e6 100644 --- a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php @@ -13,12 +13,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Methods; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; use PHPStan\Rules; use PHPStan\Testing; /** + * @covers \Ergebnis\PHPStan\Rules\Analyzer * @covers \Ergebnis\PHPStan\Rules\Methods\NoNullableReturnTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier @@ -76,6 +78,6 @@ public function testNoNullableReturnTypeDeclarationRule(): void protected function getRule(): Rules\Rule { - return new Methods\NoNullableReturnTypeDeclarationRule(); + return new Methods\NoNullableReturnTypeDeclarationRule(new Analyzer()); } } diff --git a/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php b/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php index 6783d93b..8c2e7c9d 100644 --- a/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php +++ b/test/Integration/Methods/NoParameterWithNullDefaultValueRuleTest.php @@ -13,12 +13,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Methods; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; use PHPStan\Rules; use PHPStan\Testing; /** + * @covers \Ergebnis\PHPStan\Rules\Analyzer * @covers \Ergebnis\PHPStan\Rules\Methods\NoParameterWithNullDefaultValueRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier @@ -94,6 +96,6 @@ public function testNoParameterWithNullDefaultValueRule(): void protected function getRule(): Rules\Rule { - return new Methods\NoParameterWithNullDefaultValueRule(); + return new Methods\NoParameterWithNullDefaultValueRule(new Analyzer()); } } diff --git a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php index c4f81442..fc7eceed 100644 --- a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -13,12 +13,14 @@ namespace Ergebnis\PHPStan\Rules\Test\Integration\Methods; +use Ergebnis\PHPStan\Rules\Analyzer; use Ergebnis\PHPStan\Rules\Methods; use Ergebnis\PHPStan\Rules\Test; use PHPStan\Rules; use PHPStan\Testing; /** + * @covers \Ergebnis\PHPStan\Rules\Analyzer * @covers \Ergebnis\PHPStan\Rules\Methods\NoParameterWithNullableTypeDeclarationRule * * @uses \Ergebnis\PHPStan\Rules\ErrorIdentifier @@ -76,6 +78,6 @@ public function testNoParameterWithNullableTypeDeclarationRule(): void protected function getRule(): Rules\Rule { - return new Methods\NoParameterWithNullableTypeDeclarationRule(); + return new Methods\NoParameterWithNullableTypeDeclarationRule(new Analyzer()); } } From b8992e493a0e9a28a511f9091f118f0a37575c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 8 Jan 2025 09:42:48 +0100 Subject: [PATCH 91/93] Fix: Add more test cases --- .../NoNullableReturnTypeDeclarationRule/script.php | 8 ++++++++ .../NoParameterWithNullDefaultValueRule/script.php | 4 ++-- .../script.php | 8 ++++++++ .../NoNullableReturnTypeDeclarationRule/script.php | 10 ++++++++++ .../NoParameterWithNullDefaultValueRule/script.php | 4 ++-- .../script.php | 10 ++++++++++ .../NoNullableReturnTypeDeclarationRule/script.php | 14 ++++++++++++++ .../NoParameterWithNullDefaultValueRule/script.php | 4 ++-- .../script.php | 14 ++++++++++++++ .../NoNullableReturnTypeDeclarationRuleTest.php | 4 ++++ ...arameterWithNullableTypeDeclarationRuleTest.php | 4 ++++ .../NoNullableReturnTypeDeclarationRuleTest.php | 4 ++++ ...arameterWithNullableTypeDeclarationRuleTest.php | 4 ++++ .../NoNullableReturnTypeDeclarationRuleTest.php | 4 ++++ ...arameterWithNullableTypeDeclarationRuleTest.php | 4 ++++ 15 files changed, 94 insertions(+), 6 deletions(-) diff --git a/test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/script.php b/test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/script.php index ca6393b8..e2cf7d12 100644 --- a/test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/script.php +++ b/test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/script.php @@ -19,3 +19,11 @@ $qux = function (): null|string { return 'Hello'; }; + +$quux = function (): nUlL|string { + return 'Hello'; +}; + +$quz = function (): \null|string { + return 'Hello'; +}; diff --git a/test/Fixture/Closures/NoParameterWithNullDefaultValueRule/script.php b/test/Fixture/Closures/NoParameterWithNullDefaultValueRule/script.php index 2146d8af..b847d112 100644 --- a/test/Fixture/Closures/NoParameterWithNullDefaultValueRule/script.php +++ b/test/Fixture/Closures/NoParameterWithNullDefaultValueRule/script.php @@ -19,10 +19,10 @@ return $bar; }; -$quux = function ($bar = \null) { +$quux = function ($bar = nUlL) { return $bar; }; -$quz = function ($bar = NuLl) { +$quz = function ($bar = \null) { return $bar; }; diff --git a/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/script.php b/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/script.php index 8102440e..13ec3872 100644 --- a/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/script.php +++ b/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/script.php @@ -22,3 +22,11 @@ $quux = function (null|string $bar) { return $bar; }; + +$quz = function (nUlL|string $bar) { + return $bar; +}; + +$corge = function (\null|string $bar) { + return $bar; +}; diff --git a/test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/script.php b/test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/script.php index c0220b1d..a7e85961 100644 --- a/test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/script.php +++ b/test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/script.php @@ -23,3 +23,13 @@ function quux(): null|string { return 'Hello'; } + +function quz(): nUlL|string +{ + return 'Hello'; +} + +function corge(): \null|string +{ + return 'Hello'; +} diff --git a/test/Fixture/Functions/NoParameterWithNullDefaultValueRule/script.php b/test/Fixture/Functions/NoParameterWithNullDefaultValueRule/script.php index edbcb987..8066b2c8 100644 --- a/test/Fixture/Functions/NoParameterWithNullDefaultValueRule/script.php +++ b/test/Fixture/Functions/NoParameterWithNullDefaultValueRule/script.php @@ -23,12 +23,12 @@ function qux($bar = null) return $bar; } -function quux($bar = \null) +function quux($bar = nUlL) { return $bar; } -function quz($bar = nUlL) +function quz($bar = \null) { return $bar; } diff --git a/test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/script.php b/test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/script.php index 725ed70f..eb839be6 100644 --- a/test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/script.php +++ b/test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/script.php @@ -27,3 +27,13 @@ function quux(null|string $bar) { return $bar; } + +function quz(nUlL|string $bar) +{ + return $bar; +} + +function corge(\null|string $bar) +{ + return $bar; +} diff --git a/test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/script.php b/test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/script.php index c9fa3dd8..430f243f 100644 --- a/test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/script.php +++ b/test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/script.php @@ -31,3 +31,17 @@ public function toString(): null|string return 'Hello'; } }; + +$quux = new class() { + public function toString(): nUlL|string + { + return 'Hello'; + } +}; + +$quz = new class() { + public function toString(): \null|string + { + return 'Hello'; + } +}; diff --git a/test/Fixture/Methods/NoParameterWithNullDefaultValueRule/script.php b/test/Fixture/Methods/NoParameterWithNullDefaultValueRule/script.php index e295fade..f6edf1ac 100644 --- a/test/Fixture/Methods/NoParameterWithNullDefaultValueRule/script.php +++ b/test/Fixture/Methods/NoParameterWithNullDefaultValueRule/script.php @@ -32,14 +32,14 @@ public function foo($bar = null) }; $quux = new class() { - public function foo($bar = \null) + public function foo($bar = nUlL) { return $bar; } }; $quz = new class() { - public function foo($bar = NuLl) + public function foo($bar = \null) { return $bar; } diff --git a/test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/script.php b/test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/script.php index 41588c85..f7f1471f 100644 --- a/test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/script.php +++ b/test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/script.php @@ -38,3 +38,17 @@ public function foo(null|string $bar) } }; +$quz = new class() { + public function foo(nUlL|string $bar) + { + return $bar; + } +}; + +$corge = new class() { + public function foo(\null|string $bar) + { + return $bar; + } +}; + diff --git a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php index 3bb4a879..dba8e764 100644 --- a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php @@ -44,6 +44,10 @@ public function testNoNullableReturnTypeDeclarationRule(): void 'Closure has a nullable return type declaration.', 19, ], + [ + 'Closure has a nullable return type declaration.', + 23, + ], ], ); } diff --git a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php index 52f8e04d..021580b4 100644 --- a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -44,6 +44,10 @@ public function testNoParameterWithNullableTypeDeclarationRule(): void 'Closure has parameter $bar with a nullable type declaration.', 22, ], + [ + 'Closure has parameter $bar with a nullable type declaration.', + 26, + ], ], ); } diff --git a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php index ee88039e..e87a9561 100644 --- a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php @@ -44,6 +44,10 @@ public function testNoNullableReturnTypeDeclarationRule(): void 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\quux() has a nullable return type declaration.', 22, ], + [ + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\quz() has a nullable return type declaration.', + 27, + ], ], ); } diff --git a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php index 380eefe4..b0ba677c 100644 --- a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -44,6 +44,10 @@ public function testNoParameterWithNullableTypeDeclarationRule(): void 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\quux() has parameter $bar with a nullable type declaration.', 26, ], + [ + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\quz() has parameter $bar with a nullable type declaration.', + 31, + ], ], ); } diff --git a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php index d0cad8e6..41551844 100644 --- a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php @@ -72,6 +72,10 @@ public function testNoNullableReturnTypeDeclarationRule(): void 'Method toString() in anonymous class has a nullable return type declaration.', 29, ], + [ + 'Method toString() in anonymous class has a nullable return type declaration.', + 36, + ], ], ); } diff --git a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php index fc7eceed..9eadd329 100644 --- a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -72,6 +72,10 @@ public function testNoParameterWithNullableTypeDeclarationRule(): void 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', 35, ], + [ + 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', + 42, + ], ], ); } From 62ce4bb1227c1b392e3143df4f03b7150e80c823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 8 Jan 2025 10:05:20 +0100 Subject: [PATCH 92/93] Fix: Detect cases where null is referenced with incorrect case or relative to the root namespace --- CHANGELOG.md | 5 +++++ composer-require-checker.json | 1 + src/Analyzer.php | 12 +++++++++--- .../NoNullableReturnTypeDeclarationRuleTest.php | 4 ++++ ...oParameterWithNullableTypeDeclarationRuleTest.php | 4 ++++ .../NoNullableReturnTypeDeclarationRuleTest.php | 4 ++++ ...oParameterWithNullableTypeDeclarationRuleTest.php | 4 ++++ .../NoNullableReturnTypeDeclarationRuleTest.php | 4 ++++ ...oParameterWithNullableTypeDeclarationRuleTest.php | 4 ++++ 9 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e705b8a..3a971db8 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.5.1...main`][2.5.1...main]. +### Fixed + +- Adjusted `Closures\NoNullableReturnTypeDeclarationRule`, `Closures\NoParameterWithNullableTypeDeclarationRule`, `Functions\NoNullableReturnTypeDeclarationRule`, `Functions\NoParameterWithNullableTypeDeclarationRule`, `Methods\NoNullableReturnTypeDeclarationRule`, `Methods\NoParameterWithNullableTypeDeclarationRule` to detect cases where `null` is referenced with incorrect case or relative to the root namespace ([#897]), by [@localheinz] + ## [`2.5.1`][2.5.1] For a full diff see [`2.5.0...2.5.1`][2.5.0...2.5.1]. @@ -566,6 +570,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [#890]: https://github.com/ergebnis/phpstan-rules/pull/890 [#891]: https://github.com/ergebnis/phpstan-rules/pull/891 [#895]: https://github.com/ergebnis/phpstan-rules/pull/895 +[#897]: https://github.com/ergebnis/phpstan-rules/pull/897 [@enumag]: https://github.com/enumag [@cosmastech]: https://github.com/cosmastech diff --git a/composer-require-checker.json b/composer-require-checker.json index 92f8a316..1f7f3d81 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -15,6 +15,7 @@ "PhpParser\\Node\\Expr\\Isset_", "PhpParser\\Node\\Identifier", "PhpParser\\Node\\Name", + "PhpParser\\Node\\Name\\FullyQualified", "PhpParser\\Node\\NullableType", "PhpParser\\Node\\Param", "PhpParser\\Node\\Scalar\\LNumber", diff --git a/src/Analyzer.php b/src/Analyzer.php index 4e0a6d4a..49981a2a 100644 --- a/src/Analyzer.php +++ b/src/Analyzer.php @@ -40,11 +40,17 @@ public function isNullableTypeDeclaration($typeDeclaration): bool if ($typeDeclaration instanceof Node\UnionType) { foreach ($typeDeclaration->types as $type) { - if (!$type instanceof Node\Identifier) { - continue; + if ( + $type instanceof Node\Identifier + && 'null' === $type->toLowerString() + ) { + return true; } - if ('null' === $type->toLowerString()) { + if ( + $type instanceof Node\Name\FullyQualified + && 'null' === $type->toLowerString() + ) { return true; } } diff --git a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php index dba8e764..00e03fc9 100644 --- a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php @@ -48,6 +48,10 @@ public function testNoNullableReturnTypeDeclarationRule(): void 'Closure has a nullable return type declaration.', 23, ], + [ + 'Closure has a nullable return type declaration.', + 27, + ], ], ); } diff --git a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php index 021580b4..0509288f 100644 --- a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -48,6 +48,10 @@ public function testNoParameterWithNullableTypeDeclarationRule(): void 'Closure has parameter $bar with a nullable type declaration.', 26, ], + [ + 'Closure has parameter $bar with a nullable type declaration.', + 30, + ], ], ); } diff --git a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php index e87a9561..4fc47792 100644 --- a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php @@ -48,6 +48,10 @@ public function testNoNullableReturnTypeDeclarationRule(): void 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\quz() has a nullable return type declaration.', 27, ], + [ + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\corge() has a nullable return type declaration.', + 32, + ], ], ); } diff --git a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php index b0ba677c..a705f04e 100644 --- a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -48,6 +48,10 @@ public function testNoParameterWithNullableTypeDeclarationRule(): void 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\quz() has parameter $bar with a nullable type declaration.', 31, ], + [ + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\corge() has parameter $bar with a nullable type declaration.', + 36, + ], ], ); } diff --git a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php index 41551844..1b430c0e 100644 --- a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php @@ -76,6 +76,10 @@ public function testNoNullableReturnTypeDeclarationRule(): void 'Method toString() in anonymous class has a nullable return type declaration.', 36, ], + [ + 'Method toString() in anonymous class has a nullable return type declaration.', + 43, + ], ], ); } diff --git a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php index 9eadd329..d1d9a740 100644 --- a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -76,6 +76,10 @@ public function testNoParameterWithNullableTypeDeclarationRule(): void 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', 42, ], + [ + 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', + 49, + ], ], ); } From 2754afbaf4f31ec82aab1cc0e2fdd68130a974c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 8 Jan 2025 10:28:54 +0100 Subject: [PATCH 93/93] Enhancement: Prepare release --- .github/SECURITY.md | 4 ++-- CHANGELOG.md | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/SECURITY.md b/.github/SECURITY.md index 4fb2044f..aa9fac38 100644 --- a/.github/SECURITY.md +++ b/.github/SECURITY.md @@ -4,13 +4,13 @@ The following versions of `ergebnis/phpstan-rules` have active support: -- `^2.5.1` +- `^2.5.2` ## Unsupported Versions The following versions of `ergebnis/phpstan-rules` have reached their end of life: -- `<2.5.1` +- `<2.5.2` ## Reporting a Vulnerability diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a971db8..7f419ecb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased -For a full diff see [`2.5.1...main`][2.5.1...main]. +For a full diff see [`2.5.2...main`][2.5.2...main]. + +## [`2.5.2`][2.5.2] + +For a full diff see [`2.5.1...2.5.2`][2.5.1...2.5.2]. ### Fixed @@ -456,6 +460,7 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [2.4.0]: https://github.com/ergebnis/phpstan-rules/releases/tag/2.4.0 [2.5.0]: https://github.com/ergebnis/phpstan-rules/releases/tag/2.5.0 [2.5.1]: https://github.com/ergebnis/phpstan-rules/releases/tag/2.5.1 +[2.5.2]: https://github.com/ergebnis/phpstan-rules/releases/tag/2.5.2 [362c7ea...0.1.0]: https://github.com/ergebnis/phpstan-rules/compare/362c7ea...0.1.0 [0.1.0...0.2.0]: https://github.com/ergebnis/phpstan-rules/compare/0.1.0...0.2.0 @@ -492,7 +497,8 @@ For a full diff see [`362c7ea...0.1.0`][362c7ea...0.1.0]. [2.3.0...2.4.0]: https://github.com/ergebnis/phpstan-rules/compare/2.3.0...2.4.0 [2.4.0...2.5.0]: https://github.com/ergebnis/phpstan-rules/compare/2.4.0...2.5.0 [2.5.0...2.5.1]: https://github.com/ergebnis/phpstan-rules/compare/2.5.0...2.5.1 -[2.5.1...main]: https://github.com/ergebnis/phpstan-rules/compare/2.5.1...main +[2.5.1...2.5.2]: https://github.com/ergebnis/phpstan-rules/compare/2.5.1...2.5.2 +[2.5.2...main]: https://github.com/ergebnis/phpstan-rules/compare/2.5.2...main [#1]: https://github.com/ergebnis/phpstan-rules/pull/1 [#4]: https://github.com/ergebnis/phpstan-rules/pull/4