From 19d882e9a414cc9628d2678a5c9d37c91c31bd5d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 12 Dec 2024 17:23:51 +0700 Subject: [PATCH] Allow Rector 2.0 (#145) * Temporarily remove packages that are not compatible with PHPStan 2.0 * Make rules use RuleErrorBuilder * Skip tests that depend on Rector as incomplete * Add PhpParser\PrettyPrinter\Standard to DI config file * Comment out rules that are not PHPStan 2.0 compatible * Temporarily disable steps that are not compatible with PHPStan 2.0 * Disable symplify's own error-format * fixup! Make rules use RuleErrorBuilder * fixup! Temporarily remove packages that are not compatible with PHPStan 2.0 * Revert "Temporarily disable steps that are not compatible with PHPStan 2.0" This reverts commit 18efdf5f332a92367d7e23e59f1527371505d1da. * Add Rule identifier * fixup! Skip tests that depend on Rector as incomplete * fixup! Make rules use RuleErrorBuilder * Allow Rector 2 * update downgrade script * update downgrade script * update downgrade script * update downgrade script * fix --------- Co-authored-by: USAMI Kenta --- .github/workflows/bare_run.yaml | 2 +- .github/workflows/downgraded_release.yaml | 12 ++--- ...php-72.php => rector-downgrade-php-74.php} | 2 +- .../.github/workflows/standalone_install.yaml | 2 +- build/target-repository/composer.json | 4 +- composer.json | 19 +++----- phpstan.neon | 45 ++++++++++++++----- src/Reflection/ReflectionParser.php | 2 +- .../NodeGetAttributeTypeExtension.php | 1 - src/Rules/AbstractSymplifyRule.php | 4 -- ...notateRegexClassConstWithRegexLinkRule.php | 8 ++-- .../CheckClassNamespaceFollowPsr4Rule.php | 5 ++- ...quiredInterfaceInContractNamespaceRule.php | 7 +-- .../ClassNameRespectsParentSuffixRule.php | 11 +++-- .../ForbiddenArrayMethodCallRule.php | 8 ++-- .../Domain/RequireAttributeNamespaceRule.php | 5 ++- .../Domain/RequireExceptionNamespaceRule.php | 8 ++-- .../Enum/RequireUniqueEnumConstantRule.php | 8 ++-- .../ExplicitClassPrefixSuffixRule.php | 26 +++++------ .../ForbiddenExtendOfNonAbstractClassRule.php | 5 ++- src/Rules/ForbiddenFuncCallRule.php | 10 ++--- ...orbiddenMultipleClassLikeInOneFileRule.php | 8 ++-- src/Rules/ForbiddenNodeRule.php | 9 +--- .../ForbiddenStaticClassConstFetchRule.php | 8 ++-- src/Rules/NoDynamicNameRule.php | 6 +-- .../NoEntityOutsideEntityNamespaceRule.php | 3 +- src/Rules/NoGlobalConstRule.php | 3 +- src/Rules/NoInlineStringRegexRule.php | 15 +++---- src/Rules/NoReferenceRule.php | 14 +++--- src/Rules/NoReturnArrayVariableListRule.php | 10 ++--- src/Rules/NoReturnSetterMethodRule.php | 4 +- src/Rules/PHPUnit/NoTestMocksRule.php | 6 +-- src/Rules/PreferredClassRule.php | 17 ++++--- ...ventParentMethodVisibilityOverrideRule.php | 8 ++-- .../NoClassReflectionStaticReflectionRule.php | 4 +- .../NoInstanceOfStaticReflectionRule.php | 9 ++-- .../Rector/NoLeadingBackslashInNameRule.php | 4 +- ...PhpUpgradeDowngradeRegisteredInSetRule.php | 3 +- ...deImplementsMinPhpVersionInterfaceRule.php | 4 +- ...reAssertConfigureValueObjectRectorRule.php | 12 ++--- src/Rules/RegexSuffixInRegexConstantRule.php | 17 ++++--- src/Rules/RequireAttributeNameRule.php | 2 - src/Rules/SeeAnnotationToTestRule.php | 10 ++--- src/Rules/UppercaseConstantRule.php | 8 ++-- .../config/configured_rule.neon | 2 + ...pgradeDowngradeRegisteredInSetRuleTest.php | 5 +++ ...sertConfigureValueObjectRectorRuleTest.php | 5 +++ 47 files changed, 188 insertions(+), 202 deletions(-) rename build/{rector-downgrade-php-72.php => rector-downgrade-php-74.php} (90%) diff --git a/.github/workflows/bare_run.yaml b/.github/workflows/bare_run.yaml index 68837f9a..c357dd94 100644 --- a/.github/workflows/bare_run.yaml +++ b/.github/workflows/bare_run.yaml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - php_version: ['7.2', '7.4', '8.0', '8.2'] + php_version: ['7.4', '8.0', '8.2'] steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/downgraded_release.yaml b/.github/workflows/downgraded_release.yaml index e9f6b266..5cc52efa 100644 --- a/.github/workflows/downgraded_release.yaml +++ b/.github/workflows/downgraded_release.yaml @@ -3,10 +3,10 @@ name: Downgraded Release on: push: tags: - # avoid infinite looping, skip tags that ends with ".72" + # avoid infinite looping, skip tags that ends with ".74" # see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-branches - '*' - - '!**.72' + - '!**.74' jobs: downgrade_release: @@ -33,13 +33,13 @@ jobs: - run: mkdir rector-local - run: composer require rector/rector:^0.17.1 --working-dir rector-local --ansi - # downgrade to PHP 7.2 - - run: rector-local/vendor/bin/rector process src config --config build/rector-downgrade-php-72.php --ansi + # downgrade to PHP 7.4 + - run: rector-local/vendor/bin/rector process src config --config build/rector-downgrade-php-74.php --ansi # clear the dev files - run: rm -rf tests rector-local ecs.php phpstan.neon phpunit.xml .editorconfig - # copy PHP 7.2 composer + workflows + # copy PHP 7.4 composer + workflows - run: cp -r build/target-repository/. . # clear the dev files @@ -57,7 +57,7 @@ jobs: run: | # separate a "git add" to add untracked (new) files too git add --all - git commit -m "release PHP 7.2 downgraded" + git commit -m "release PHP 7.4 downgraded" # force push tag, so there is only 1 version git tag "${GITHUB_REF#refs/tags/}" --force diff --git a/build/rector-downgrade-php-72.php b/build/rector-downgrade-php-74.php similarity index 90% rename from build/rector-downgrade-php-72.php rename to build/rector-downgrade-php-74.php index 34d0c266..e8b7eef9 100644 --- a/build/rector-downgrade-php-72.php +++ b/build/rector-downgrade-php-74.php @@ -11,7 +11,7 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->parallel(); - $rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_72]); + $rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_74]); $rectorConfig->ruleWithConfiguration(RemoveInterfacesRector::class, [ DocumentedRuleInterface::class, diff --git a/build/target-repository/.github/workflows/standalone_install.yaml b/build/target-repository/.github/workflows/standalone_install.yaml index 3dbe325c..f393951f 100644 --- a/build/target-repository/.github/workflows/standalone_install.yaml +++ b/build/target-repository/.github/workflows/standalone_install.yaml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: false matrix: - php_version: ['7.2', '7.3', '7.4', '8.0'] + php_version: ['7.4', '8.0'] steps: # prepare empty composer.json that allows the phpstan extension plugin diff --git a/build/target-repository/composer.json b/build/target-repository/composer.json index d7e0856e..5f56a524 100644 --- a/build/target-repository/composer.json +++ b/build/target-repository/composer.json @@ -4,9 +4,9 @@ "description": "Set of Symplify rules for PHPStan", "license": "MIT", "require": { - "php": "^7.2|^8.0", + "php": "^7.4|^8.0", "nette/utils": "^3.2.9 || ^4.0", - "phpstan/phpstan": "^1.10.30", + "phpstan/phpstan": "^2.0", "webmozart/assert": "^1.11" }, "autoload": { diff --git a/composer.json b/composer.json index 7d6ecb53..26edb434 100644 --- a/composer.json +++ b/composer.json @@ -7,21 +7,18 @@ "php": ">=8.1", "nette/utils": "^3.2.9 || ^4.0", "webmozart/assert": "^1.11", - "phpstan/phpstan": "^1.11", + "phpstan/phpstan": "^2.0", "symplify/rule-doc-generator-contracts": "^11.2" }, "require-dev": { - "nikic/php-parser": "^4.19", - "symplify/phpstan-extensions": "^11.4", + "nikic/php-parser": "^5.0", "symplify/rule-doc-generator": "^12.2", "phpunit/phpunit": "^10.5", "symfony/framework-bundle": "6.1.*", - "rector/rector": "^1.2.3", "symplify/easy-coding-standard": "^12.3", - "phpstan/extension-installer": "^1.4", - "tomasvotruba/class-leak": "^0.2", - "tomasvotruba/unused-public": "^0.3.10", - "tomasvotruba/type-coverage": "^0.3.1" + "tomasvotruba/class-leak": "^1.2", + "rector/rector": "^2.0", + "phpstan/extension-installer": "^1.4" }, "autoload": { "psr-4": { @@ -36,10 +33,6 @@ "stubs" ], "files": [ - "tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/Fixture/SomePhpFeatureRector.php", - "vendor/rector/rector/src/Contract/Rector/RectorInterface.php", - "vendor/rector/rector/src/Contract/Rector/ConfigurableRectorInterface.php", - "vendor/rector/rector/vendor/rector/rector-downgrade-php/src/Set/ValueObject/DowngradeSetList.php" ] }, "extra": { @@ -58,7 +51,7 @@ "scripts": { "check-cs": "vendor/bin/ecs check --ansi", "fix-cs": "vendor/bin/ecs check --fix --ansi", - "phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify", + "phpstan": "vendor/bin/phpstan analyse --ansi", "rector": "vendor/bin/rector process --dry-run --ansi", "docs": "vendor/bin/rule-doc-generator generate src --readme --ansi" } diff --git a/phpstan.neon b/phpstan.neon index db7f3f3b..00772e43 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,6 +3,8 @@ includes: - config/naming-rules.neon parameters: + treatPhpDocTypesAsCertain: false + level: 8 paths: @@ -20,15 +22,15 @@ parameters: - */Fixture/* # https://github.com/TomasVotruba/unused-public - unused_public: - methods: true - properties: true - constants: true + # unused_public: + # methods: true + # properties: true + # constants: true - type_coverage: - return: 99 - param: 99 - property: 99 + # type_coverage: + # return: 99 + # param: 99 + # property: 99 ignoreErrors: # needless generics @@ -38,8 +40,6 @@ parameters: - '#Method Symplify\\PHPStanRules\\Reflection\\ReflectionParser\:\:parseNativeClassReflection\(\) has parameter \$reflectionClass with generic class ReflectionClass but does not specify its types\: T#' - - '#Method Symplify\\PHPStanRules\\NodeFinder\\TypeAwareNodeFinder\:\:findFirstInstanceOf\(\) should return \(TNode of PhpParser\\Node\)\|null but returns PhpParser\\Node\|null#' - # overly detailed - '#Class Symplify\\PHPStanRules\\(.*?) extends generic class PHPStan\\Testing\\RuleTestCase but does not specify its types\: TRule#' - '#Method Symplify\\PHPStanRules\\(.*?)\:\:getRule\(\) return type with generic interface PHPStan\\Rules\\Rule does not specify its types\: TNodeType#' @@ -50,5 +50,26 @@ parameters: # overly detailed - '#Class Symplify\\PHPStanRules\\Collector\\(.*?) implements generic interface PHPStan\\Collectors\\Collector but does not specify its types\: TNodeType, TValue#' - # used in tests - - '#Public constant "(.*?)\:\:ERROR_MESSAGE" is never used#' + - + identifier: argument.type + + - + identifier: phpstanApi.instanceofType + + - + identifier: return.type + + - + identifier: class.notFound + + - + identifier: phpstanApi.runtimeReflection + + - + identifier: phpstanApi.instanceofAssumption + + - + identifier: generics.wrongParent + + - + identifier: method.childReturnType diff --git a/src/Reflection/ReflectionParser.php b/src/Reflection/ReflectionParser.php index a2c6bd41..15956092 100644 --- a/src/Reflection/ReflectionParser.php +++ b/src/Reflection/ReflectionParser.php @@ -31,7 +31,7 @@ public function __construct( private readonly TypeAwareNodeFinder $typeAwareNodeFinder ) { $parserFactory = new ParserFactory(); - $this->parser = $parserFactory->create(ParserFactory::PREFER_PHP7); + $this->parser = $parserFactory->createForNewestSupportedVersion(); } public function parseMethodReflection(ReflectionMethod|MethodReflection $reflectionMethod): ?ClassMethod diff --git a/src/ReturnTypeExtension/NodeGetAttributeTypeExtension.php b/src/ReturnTypeExtension/NodeGetAttributeTypeExtension.php index a52e873e..9e3be828 100644 --- a/src/ReturnTypeExtension/NodeGetAttributeTypeExtension.php +++ b/src/ReturnTypeExtension/NodeGetAttributeTypeExtension.php @@ -13,7 +13,6 @@ use PhpParser\Node\Scalar\String_; use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; -use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; diff --git a/src/Rules/AbstractSymplifyRule.php b/src/Rules/AbstractSymplifyRule.php index 35ef5530..e7233211 100644 --- a/src/Rules/AbstractSymplifyRule.php +++ b/src/Rules/AbstractSymplifyRule.php @@ -7,7 +7,6 @@ use PhpParser\Node; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; -use PHPStan\Rules\RuleError; use Symplify\PHPStanRules\Contract\ManyNodeRuleInterface; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; @@ -24,9 +23,6 @@ public function getNodeType(): string return Node::class; } - /** - * @return string[]|RuleError[] - */ public function processNode(Node $node, Scope $scope): array { if ($this->shouldSkipNode($node)) { diff --git a/src/Rules/AnnotateRegexClassConstWithRegexLinkRule.php b/src/Rules/AnnotateRegexClassConstWithRegexLinkRule.php index 7b6b3582..e624a06e 100644 --- a/src/Rules/AnnotateRegexClassConstWithRegexLinkRule.php +++ b/src/Rules/AnnotateRegexClassConstWithRegexLinkRule.php @@ -11,11 +11,13 @@ use PhpParser\Node\Stmt\ClassConst; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\AnnotateRegexClassConstWithRegexLinkRule\AnnotateRegexClassConstWithRegexLinkRuleTest */ final class AnnotateRegexClassConstWithRegexLinkRule implements Rule, DocumentedRuleInterface @@ -31,9 +33,6 @@ final class AnnotateRegexClassConstWithRegexLinkRule implements Rule, Documented */ private const ALL_MODIFIERS = 'imsxeADSUXJu'; - /** - * @return class-string - */ public function getNodeType(): string { return ClassConst::class; @@ -41,7 +40,6 @@ public function getNodeType(): string /** * @param ClassConst $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -69,7 +67,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/CheckClassNamespaceFollowPsr4Rule.php b/src/Rules/CheckClassNamespaceFollowPsr4Rule.php index f09e453e..d4c40840 100644 --- a/src/Rules/CheckClassNamespaceFollowPsr4Rule.php +++ b/src/Rules/CheckClassNamespaceFollowPsr4Rule.php @@ -9,6 +9,7 @@ use PhpParser\Node\Stmt\ClassLike; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\PHPStanRules\Composer\ClassNamespaceMatcher; use Symplify\PHPStanRules\Composer\ComposerAutoloadResolver; use Symplify\PHPStanRules\Composer\Psr4PathValidator; @@ -17,6 +18,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\CheckClassNamespaceFollowPsr4Rule\CheckClassNamespaceFollowPsr4RuleTest */ final class CheckClassNamespaceFollowPsr4Rule implements Rule, DocumentedRuleInterface @@ -49,7 +51,6 @@ public function getNodeType(): string /** * @param ClassLike $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -87,7 +88,7 @@ public function processNode(Node $node, Scope $scope): array $namespacePart = substr($namespaceBeforeClass, 0, -1); $errorMessage = sprintf(self::ERROR_MESSAGE, $namespacePart); - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->identifier('check.classnamespacepsr4')->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php b/src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php index c84e3424..2658a039 100644 --- a/src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php +++ b/src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php @@ -9,6 +9,7 @@ use PhpParser\Node\Stmt\Interface_; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -30,9 +31,6 @@ final class CheckRequiredInterfaceInContractNamespaceRule implements Rule, Docum */ private const A_CONTRACT_NAMESPACE_REGEX = '#\bContracts?\b#'; - /** - * @return class-string - */ public function getNodeType(): string { return Interface_::class; @@ -40,7 +38,6 @@ public function getNodeType(): string /** * @param Interface_ $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -53,7 +50,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/ClassNameRespectsParentSuffixRule.php b/src/Rules/ClassNameRespectsParentSuffixRule.php index 298a07da..3e71032d 100644 --- a/src/Rules/ClassNameRespectsParentSuffixRule.php +++ b/src/Rules/ClassNameRespectsParentSuffixRule.php @@ -12,6 +12,8 @@ use PHPStan\Node\InClassNode; use PHPStan\Reflection\ClassReflection; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleError; +use PHPStan\Rules\RuleErrorBuilder; use PHPUnit\Framework\TestCase; use Rector\Rector\AbstractRector; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -23,6 +25,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\ClassNameRespectsParentSuffixRule\ClassNameRespectsParentSuffixRuleTest */ final class ClassNameRespectsParentSuffixRule implements Rule, DocumentedRuleInterface, ConfigurableRuleInterface @@ -62,9 +65,6 @@ public function __construct( $this->parentClasses = array_merge($parentClasses, self::DEFAULT_PARENT_CLASSES); } - /** - * @return class-string - */ public function getNodeType(): string { return InClassNode::class; @@ -72,7 +72,6 @@ public function getNodeType(): string /** * @param InClassNode $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -117,7 +116,7 @@ class SomeCommand extends Command } /** - * @return array + * @return list */ private function processClassNameAndShort(ClassReflection $classReflection): array { @@ -132,7 +131,7 @@ private function processClassNameAndShort(ClassReflection $classReflection): arr } $errorMessage = sprintf(self::ERROR_MESSAGE, $expectedSuffix); - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->build()]; } return []; diff --git a/src/Rules/Complexity/ForbiddenArrayMethodCallRule.php b/src/Rules/Complexity/ForbiddenArrayMethodCallRule.php index 872afa46..63d6877a 100644 --- a/src/Rules/Complexity/ForbiddenArrayMethodCallRule.php +++ b/src/Rules/Complexity/ForbiddenArrayMethodCallRule.php @@ -9,6 +9,7 @@ use PhpParser\Node\Expr\ArrayItem; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\TypeWithClassName; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; @@ -16,6 +17,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\Complexity\ForbiddenArrayMethodCallRule\ForbiddenArrayMethodCallRuleTest */ final class ForbiddenArrayMethodCallRule implements Rule, DocumentedRuleInterface @@ -25,9 +27,6 @@ final class ForbiddenArrayMethodCallRule implements Rule, DocumentedRuleInterfac */ public const ERROR_MESSAGE = 'Array method calls [$this, "method"] are not allowed. Use explicit method instead to help PhpStorm, PHPStan and Rector understand your code'; - /** - * @return class-string - */ public function getNodeType(): string { return Array_::class; @@ -35,7 +34,6 @@ public function getNodeType(): string /** * @param Array_ $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -58,7 +56,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/Domain/RequireAttributeNamespaceRule.php b/src/Rules/Domain/RequireAttributeNamespaceRule.php index bab902cc..cb2fe1df 100644 --- a/src/Rules/Domain/RequireAttributeNamespaceRule.php +++ b/src/Rules/Domain/RequireAttributeNamespaceRule.php @@ -8,11 +8,13 @@ use PHPStan\Analyser\Scope; use PHPStan\Node\InClassNode; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\Domain\RequireAttributeNamespaceRule\RequireAttributeNamespaceRuleTest */ final class RequireAttributeNamespaceRule implements Rule, DocumentedRuleInterface @@ -59,7 +61,6 @@ public function getNodeType(): string /** * @param InClassNode $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -74,6 +75,6 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } } diff --git a/src/Rules/Domain/RequireExceptionNamespaceRule.php b/src/Rules/Domain/RequireExceptionNamespaceRule.php index afcd522c..d4f8d304 100644 --- a/src/Rules/Domain/RequireExceptionNamespaceRule.php +++ b/src/Rules/Domain/RequireExceptionNamespaceRule.php @@ -8,11 +8,13 @@ use PHPStan\Analyser\Scope; use PHPStan\Node\InClassNode; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\Domain\RequireExceptionNamespaceRule\RequireExceptionNamespaceRuleTest */ final class RequireExceptionNamespaceRule implements Rule, DocumentedRuleInterface @@ -48,9 +50,6 @@ final class SomeException extends Exception ]); } - /** - * @return class-string - */ public function getNodeType(): string { return InClassNode::class; @@ -58,7 +57,6 @@ public function getNodeType(): string /** * @param InClassNode $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -77,6 +75,6 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } } diff --git a/src/Rules/Enum/RequireUniqueEnumConstantRule.php b/src/Rules/Enum/RequireUniqueEnumConstantRule.php index 49d722b0..9568f85c 100644 --- a/src/Rules/Enum/RequireUniqueEnumConstantRule.php +++ b/src/Rules/Enum/RequireUniqueEnumConstantRule.php @@ -9,6 +9,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Node\InClassNode; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\Constant\ConstantStringType; use Symplify\PHPStanRules\NodeAnalyzer\EnumAnalyzer; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; @@ -16,6 +17,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\Enum\RequireUniqueEnumConstantRule\RequireUniqueEnumConstantRuleTest */ final class RequireUniqueEnumConstantRule implements Rule, DocumentedRuleInterface @@ -30,9 +32,6 @@ public function __construct( ) { } - /** - * @return class-string - */ public function getNodeType(): string { return InClassNode::class; @@ -40,7 +39,6 @@ public function getNodeType(): string /** * @param InClassNode $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -60,7 +58,7 @@ public function processNode(Node $node, Scope $scope): array } $errorMessage = sprintf(self::ERROR_MESSAGE, implode('", "', $duplicatedConstantValues)); - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/Explicit/ExplicitClassPrefixSuffixRule.php b/src/Rules/Explicit/ExplicitClassPrefixSuffixRule.php index 4768b1a5..263970e2 100644 --- a/src/Rules/Explicit/ExplicitClassPrefixSuffixRule.php +++ b/src/Rules/Explicit/ExplicitClassPrefixSuffixRule.php @@ -12,12 +12,14 @@ use PhpParser\Node\Stmt\Trait_; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use function str_ends_with; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\Explicit\ExplicitClassPrefixSuffixRule\ExplicitClassPrefixSuffixRuleTest */ final class ExplicitClassPrefixSuffixRule implements Rule, DocumentedRuleInterface @@ -40,9 +42,6 @@ final class ExplicitClassPrefixSuffixRule implements Rule, DocumentedRuleInterfa */ public const ABSTRACT_ERROR_MESSAGE = 'Abstract class must be prefixed by "Abstract" exclusively'; - /** - * @return class-string - */ public function getNodeType(): string { return ClassLike::class; @@ -89,7 +88,6 @@ abstract class AbstractClass /** * @param ClassLike $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -113,7 +111,7 @@ public function processNode(Node $node, Scope $scope): array } /** - * @return string[] + * @return list */ private function processInterfaceSuffix(Identifier $identifier): array { @@ -122,14 +120,14 @@ private function processInterfaceSuffix(Identifier $identifier): array } if (str_ends_with($identifier->toString(), 'Trait')) { - return [self::TRAIT_ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::TRAIT_ERROR_MESSAGE)->build()]; } - return [self::INTERFACE_ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::INTERFACE_ERROR_MESSAGE)->build()]; } /** - * @return string[] + * @return list */ private function processTraitSuffix(Identifier $identifier): array { @@ -137,28 +135,28 @@ private function processTraitSuffix(Identifier $identifier): array return []; } - return [self::TRAIT_ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::TRAIT_ERROR_MESSAGE)->build()]; } /** - * @return string[] + * @return list */ private function processClassSuffix(Identifier $identifier, bool $isAbstract): array { if ($isAbstract && ! str_starts_with($identifier->toString(), 'Abstract')) { - return [self::ABSTRACT_ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ABSTRACT_ERROR_MESSAGE)->build()]; } if (! $isAbstract && str_starts_with($identifier->toString(), 'Abstract')) { - return [self::ABSTRACT_ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ABSTRACT_ERROR_MESSAGE)->build()]; } if (str_ends_with($identifier->toString(), 'Interface')) { - return [self::INTERFACE_ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::INTERFACE_ERROR_MESSAGE)->build()]; } if (str_ends_with($identifier->toString(), 'Trait')) { - return [self::TRAIT_ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::TRAIT_ERROR_MESSAGE)->build()]; } return []; diff --git a/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php b/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php index 20c622f8..9e79bfdd 100644 --- a/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php +++ b/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php @@ -9,11 +9,13 @@ use PHPStan\Node\InClassNode; use PHPStan\Reflection\ClassReflection; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenExtendOfNonAbstractClassRule\ForbiddenExtendOfNonAbstractClassRuleTest */ final class ForbiddenExtendOfNonAbstractClassRule implements Rule, DocumentedRuleInterface @@ -33,7 +35,6 @@ public function getNodeType(): string /** * @param InClassNode $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -63,7 +64,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/ForbiddenFuncCallRule.php b/src/Rules/ForbiddenFuncCallRule.php index 6b633d1c..519de861 100644 --- a/src/Rules/ForbiddenFuncCallRule.php +++ b/src/Rules/ForbiddenFuncCallRule.php @@ -9,6 +9,7 @@ use PhpParser\Node\Name; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\ObjectType; use PHPStan\Type\TypeCombinator; use SimpleXMLElement; @@ -21,6 +22,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenFuncCallRule\ForbiddenFuncCallRuleTest */ final class ForbiddenFuncCallRule implements Rule, DocumentedRuleInterface, ConfigurableRuleInterface @@ -31,7 +33,7 @@ final class ForbiddenFuncCallRule implements Rule, DocumentedRuleInterface, Conf public const ERROR_MESSAGE = 'Function "%s()" cannot be used/left in the code'; /** - * @param string[]|array $forbiddenFunctions + * @param array $forbiddenFunctions */ public function __construct( private readonly array $forbiddenFunctions, @@ -40,9 +42,6 @@ public function __construct( ) { } - /** - * @return class-string - */ public function getNodeType(): string { return FuncCall::class; @@ -50,7 +49,6 @@ public function getNodeType(): string /** * @param FuncCall $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -72,7 +70,7 @@ public function processNode(Node $node, Scope $scope): array } $errorMessage = $this->createErrorMessage($requiredWithMessage, $funcName); - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->build()]; } return []; diff --git a/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php b/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php index 19afa4d9..fedf59ca 100644 --- a/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php +++ b/src/Rules/ForbiddenMultipleClassLikeInOneFileRule.php @@ -11,11 +11,13 @@ use PHPStan\Analyser\Scope; use PHPStan\Node\FileNode; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenMultipleClassLikeInOneFileRule\ForbiddenMultipleClassLikeInOneFileRuleTest */ final class ForbiddenMultipleClassLikeInOneFileRule implements Rule, DocumentedRuleInterface @@ -32,9 +34,6 @@ public function __construct( $this->nodeFinder = new NodeFinder(); } - /** - * @return class-string - */ public function getNodeType(): string { return FileNode::class; @@ -42,7 +41,6 @@ public function getNodeType(): string /** * @param FileNode $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -62,7 +60,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/ForbiddenNodeRule.php b/src/Rules/ForbiddenNodeRule.php index a2576f51..1a0bd5f2 100644 --- a/src/Rules/ForbiddenNodeRule.php +++ b/src/Rules/ForbiddenNodeRule.php @@ -11,6 +11,7 @@ use PhpParser\PrettyPrinter\Standard; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\ConfigurableRuleInterface; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; @@ -45,17 +46,11 @@ public function __construct( $this->forbiddenNodes = $forbiddenNodes; } - /** - * @return class-string - */ public function getNodeType(): string { return Node::class; } - /** - * @return string[] - */ public function processNode(Node $node, Scope $scope): array { foreach ($this->forbiddenNodes as $forbiddenNode) { @@ -72,7 +67,7 @@ public function processNode(Node $node, Scope $scope): array $errorMessage = sprintf(self::ERROR_MESSAGE, $contents); - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->build()]; } return []; diff --git a/src/Rules/ForbiddenStaticClassConstFetchRule.php b/src/Rules/ForbiddenStaticClassConstFetchRule.php index aae53e98..4d2de5eb 100644 --- a/src/Rules/ForbiddenStaticClassConstFetchRule.php +++ b/src/Rules/ForbiddenStaticClassConstFetchRule.php @@ -9,11 +9,13 @@ use PhpParser\Node\Name; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenStaticClassConstFetchRule\ForbiddenStaticClassConstFetchRuleTest */ final class ForbiddenStaticClassConstFetchRule implements Rule, DocumentedRuleInterface @@ -23,9 +25,6 @@ final class ForbiddenStaticClassConstFetchRule implements Rule, DocumentedRuleIn */ public const ERROR_MESSAGE = 'Avoid static access of constants, as they can change value. Use interface and contract method instead'; - /** - * @return class-string - */ public function getNodeType(): string { return ClassConstFetch::class; @@ -33,7 +32,6 @@ public function getNodeType(): string /** * @param ClassConstFetch $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -45,7 +43,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/NoDynamicNameRule.php b/src/Rules/NoDynamicNameRule.php index 35783553..bad7204b 100644 --- a/src/Rules/NoDynamicNameRule.php +++ b/src/Rules/NoDynamicNameRule.php @@ -14,6 +14,7 @@ use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Identifier; use PHPStan\Analyser\Scope; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\PHPStanRules\TypeAnalyzer\CallableTypeAnalyzer; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -50,7 +51,6 @@ public function getNodeTypes(): array /** * @param MethodCall|StaticCall|FuncCall|StaticPropertyFetch|PropertyFetch|ClassConstFetch $node - * @return string[] */ public function process(Node $node, Scope $scope): array { @@ -67,7 +67,7 @@ public function process(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } if (! $node->name instanceof Expr) { @@ -78,7 +78,7 @@ public function process(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/NoEntityOutsideEntityNamespaceRule.php b/src/Rules/NoEntityOutsideEntityNamespaceRule.php index 44983726..936102a8 100644 --- a/src/Rules/NoEntityOutsideEntityNamespaceRule.php +++ b/src/Rules/NoEntityOutsideEntityNamespaceRule.php @@ -9,6 +9,7 @@ use PhpParser\Node\Stmt\Class_; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -48,7 +49,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/NoGlobalConstRule.php b/src/Rules/NoGlobalConstRule.php index 043f56d9..2d28944b 100644 --- a/src/Rules/NoGlobalConstRule.php +++ b/src/Rules/NoGlobalConstRule.php @@ -8,6 +8,7 @@ use PhpParser\Node\Stmt\Const_; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -33,7 +34,7 @@ public function getNodeType(): string */ public function processNode(Node $node, Scope $scope): array { - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/NoInlineStringRegexRule.php b/src/Rules/NoInlineStringRegexRule.php index 32e75cd8..572be954 100644 --- a/src/Rules/NoInlineStringRegexRule.php +++ b/src/Rules/NoInlineStringRegexRule.php @@ -12,6 +12,8 @@ use PhpParser\Node\Scalar\String_; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleError; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\PHPStanRules\NodeAnalyzer\RegexFuncCallAnalyzer; use Symplify\PHPStanRules\NodeAnalyzer\RegexStaticCallAnalyzer; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; @@ -19,6 +21,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\NoInlineStringRegexRule\NoInlineStringRegexRuleTest */ final class NoInlineStringRegexRule implements Rule, DocumentedRuleInterface @@ -34,9 +37,6 @@ public function __construct( ) { } - /** - * @return class-string - */ public function getNodeType(): string { return CallLike::class; @@ -44,7 +44,6 @@ public function getNodeType(): string /** * @param CallLike $node - * @return mixed[]|string[] */ public function processNode(Node $node, Scope $scope): array { @@ -92,7 +91,7 @@ public function run($value) } /** - * @return string[] + * @return list */ private function processRegexFuncCall(FuncCall $funcCall): array { @@ -107,11 +106,11 @@ private function processRegexFuncCall(FuncCall $funcCall): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } /** - * @return string[] + * @return list */ private function processRegexStaticCall(StaticCall $staticCall): array { @@ -133,6 +132,6 @@ private function processRegexStaticCall(StaticCall $staticCall): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } } diff --git a/src/Rules/NoReferenceRule.php b/src/Rules/NoReferenceRule.php index 47b584e4..d2ecb5cd 100644 --- a/src/Rules/NoReferenceRule.php +++ b/src/Rules/NoReferenceRule.php @@ -4,9 +4,10 @@ namespace Symplify\PHPStanRules\Rules; +use PHPStan\Rules\RuleError; use PhpParser\Node; use PhpParser\Node\Arg; -use PhpParser\Node\Expr\ArrayItem; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\AssignRef; use PhpParser\Node\Expr\Closure; @@ -15,9 +16,11 @@ use PhpParser\Node\Stmt\Foreach_; use PhpParser\Node\Stmt\Function_; use PHPStan\Analyser\Scope; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\PHPStanRules\ParentClassMethodNodeResolver; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; +use function array_map; /** * @see \Symplify\PHPStanRules\Tests\Rules\NoReferenceRule\NoReferenceRuleTest @@ -34,9 +37,6 @@ public function __construct( ) { } - /** - * @return array> - */ public function getNodeTypes(): array { return [ @@ -53,7 +53,6 @@ public function getNodeTypes(): array /** * @param ClassMethod|Function_|AssignRef|Arg|Foreach_|ArrayItem|ArrowFunction|Closure $node - * @return string[] */ public function process(Node $node, Scope $scope): array { @@ -68,7 +67,10 @@ public function process(Node $node, Scope $scope): array $paramErrorMessage = $this->collectParamErrorMessages($node, $scope); $errorMessages = array_merge($errorMessages, $paramErrorMessage); - return array_unique($errorMessages); + return array_map( + static fn ($message): RuleError => RuleErrorBuilder::message($message)->build(), + array_unique($errorMessages), + ); } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/NoReturnArrayVariableListRule.php b/src/Rules/NoReturnArrayVariableListRule.php index f5055602..94f1466a 100644 --- a/src/Rules/NoReturnArrayVariableListRule.php +++ b/src/Rules/NoReturnArrayVariableListRule.php @@ -14,6 +14,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\PHPStanRules\ParentClassMethodNodeResolver; use Symplify\PHPStanRules\Testing\StaticPHPUnitEnvironment; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; @@ -21,6 +22,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\NoReturnArrayVariableListRule\NoReturnArrayVariableListRuleTest */ final class NoReturnArrayVariableListRule implements Rule, DocumentedRuleInterface @@ -41,9 +43,6 @@ public function __construct( ) { } - /** - * @return class-string - */ public function getNodeType(): string { return Return_::class; @@ -51,7 +50,6 @@ public function getNodeType(): string /** * @param Return_ $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -72,7 +70,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } public function getRuleDefinition(): RuleDefinition @@ -156,7 +154,7 @@ private function resolveExprCount(Array_ $array): int continue; } - if ($item->unpack === true) { + if ($item->unpack) { continue; } diff --git a/src/Rules/NoReturnSetterMethodRule.php b/src/Rules/NoReturnSetterMethodRule.php index 0a4ee1ba..ff4a6220 100644 --- a/src/Rules/NoReturnSetterMethodRule.php +++ b/src/Rules/NoReturnSetterMethodRule.php @@ -12,6 +12,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\PHPStanRules\NodeFinder\TypeAwareNodeFinder; use Symplify\PHPStanRules\NodeVisitor\HasScopedReturnNodeVisitor; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; @@ -19,6 +20,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\NoReturnSetterMethodRule\NoReturnSetterMethodRuleTest */ final class NoReturnSetterMethodRule implements Rule, DocumentedRuleInterface @@ -75,7 +77,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/PHPUnit/NoTestMocksRule.php b/src/Rules/PHPUnit/NoTestMocksRule.php index bfc705e4..a07cca16 100644 --- a/src/Rules/PHPUnit/NoTestMocksRule.php +++ b/src/Rules/PHPUnit/NoTestMocksRule.php @@ -9,6 +9,7 @@ use PhpParser\Node\Identifier; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\ObjectType; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -38,9 +39,6 @@ public function __construct( ) { } - /** - * @return class-string - */ public function getNodeType(): string { return MethodCall::class; @@ -71,7 +69,7 @@ public function processNode(Node $node, Scope $scope): array $errorMessage = sprintf(self::ERROR_MESSAGE, $mockedObjectType->getClassName()); - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/PreferredClassRule.php b/src/Rules/PreferredClassRule.php index c7a703a0..635fb1b3 100644 --- a/src/Rules/PreferredClassRule.php +++ b/src/Rules/PreferredClassRule.php @@ -14,12 +14,15 @@ use PHPStan\Analyser\Scope; use PHPStan\Node\InClassNode; use PHPStan\Reflection\ClassReflection; +use PHPStan\Rules\RuleError; +use PHPStan\Rules\RuleErrorBuilder; use SplFileInfo; use Symplify\RuleDocGenerator\Contract\ConfigurableRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\PreferredClassRule\PreferredClassRuleTest */ final class PreferredClassRule extends AbstractSymplifyRule implements ConfigurableRuleInterface @@ -37,9 +40,6 @@ public function __construct( ) { } - /** - * @return array> - */ public function getNodeTypes(): array { return [New_::class, Name::class, InClassNode::class, StaticCall::class, Instanceof_::class]; @@ -47,7 +47,6 @@ public function getNodeTypes(): array /** * @param New_|Name|InClassNode|StaticCall|Instanceof_ $node - * @return string[] */ public function process(Node $node, Scope $scope): array { @@ -113,7 +112,7 @@ private function processNew(New_ $new): array } /** - * @return string[] + * @return list */ private function processClass(InClassNode $inClassNode): array { @@ -138,14 +137,14 @@ private function processClass(InClassNode $inClassNode): array } $errorMessage = sprintf(self::ERROR_MESSAGE, $oldClass, $prefferedClass); - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->build()]; } return []; } /** - * @return string[] + * @return list */ private function processClassName(string $className): array { @@ -155,14 +154,14 @@ private function processClassName(string $className): array } $errorMessage = sprintf(self::ERROR_MESSAGE, $oldClass, $prefferedClass); - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->build()]; } return []; } /** - * @return string[] + * @return list */ private function processExprWithClass(StaticCall|Instanceof_ $node): array { diff --git a/src/Rules/PreventParentMethodVisibilityOverrideRule.php b/src/Rules/PreventParentMethodVisibilityOverrideRule.php index a6e8c489..7305c1c9 100644 --- a/src/Rules/PreventParentMethodVisibilityOverrideRule.php +++ b/src/Rules/PreventParentMethodVisibilityOverrideRule.php @@ -11,11 +11,13 @@ use PHPStan\Reflection\ExtendedMethodReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\PreventParentMethodVisibilityOverrideRule\PreventParentMethodVisibilityOverrideRuleTest */ final class PreventParentMethodVisibilityOverrideRule implements Rule, DocumentedRuleInterface @@ -30,9 +32,6 @@ public function __construct( ) { } - /** - * @return class-string - */ public function getNodeType(): string { return ClassMethod::class; @@ -40,7 +39,6 @@ public function getNodeType(): string /** * @param ClassMethod $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -74,7 +72,7 @@ public function processNode(Node $node, Scope $scope): array $methodVisibility = $this->resolveReflectionMethodVisibilityAsStrings($parentReflectionMethod); $errorMessage = sprintf(self::ERROR_MESSAGE, $methodName, $methodVisibility); - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->build()]; } return []; diff --git a/src/Rules/Rector/NoClassReflectionStaticReflectionRule.php b/src/Rules/Rector/NoClassReflectionStaticReflectionRule.php index 7bab3f52..6dd3d030 100644 --- a/src/Rules/Rector/NoClassReflectionStaticReflectionRule.php +++ b/src/Rules/Rector/NoClassReflectionStaticReflectionRule.php @@ -9,6 +9,7 @@ use PhpParser\Node\Name; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use ReflectionClass; use Symplify\PHPStanRules\TypeAnalyzer\RectorAllowedAutoloadedTypeAnalyzer; @@ -31,7 +32,6 @@ public function getNodeType(): string /** * @param New_ $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -54,6 +54,6 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } } diff --git a/src/Rules/Rector/NoInstanceOfStaticReflectionRule.php b/src/Rules/Rector/NoInstanceOfStaticReflectionRule.php index 14ee0e8b..e42e3b22 100644 --- a/src/Rules/Rector/NoInstanceOfStaticReflectionRule.php +++ b/src/Rules/Rector/NoInstanceOfStaticReflectionRule.php @@ -11,6 +11,7 @@ use PhpParser\Node\Name; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\Type; use Symplify\PHPStanRules\TypeAnalyzer\RectorAllowedAutoloadedTypeAnalyzer; @@ -29,17 +30,13 @@ final class NoInstanceOfStaticReflectionRule implements Rule */ public const ERROR_MESSAGE = 'Instead of "instanceof/is_a()" use ReflectionProvider service or "(new ObjectType())->isSuperTypeOf()" for static reflection to work'; - /** - * @return class-string - */ public function getNodeType(): string { return Expr::class; } /** - * @param Node\Expr $node - * @return string[] + * @param Expr $node */ public function processNode(Node $node, Scope $scope): array { @@ -56,7 +53,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } private function resolveExprStaticType(FuncCall|Instanceof_ $node, Scope $scope): ?Type diff --git a/src/Rules/Rector/NoLeadingBackslashInNameRule.php b/src/Rules/Rector/NoLeadingBackslashInNameRule.php index 27f0ac06..ead3c054 100644 --- a/src/Rules/Rector/NoLeadingBackslashInNameRule.php +++ b/src/Rules/Rector/NoLeadingBackslashInNameRule.php @@ -11,6 +11,7 @@ use PhpParser\Node\Name\Relative; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\Constant\ConstantStringType; /** @@ -32,7 +33,6 @@ public function getNodeType(): string /** * @param New_ $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -60,6 +60,6 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } } diff --git a/src/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule.php b/src/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule.php index de3d1d5b..93718450 100644 --- a/src/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule.php +++ b/src/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule.php @@ -43,7 +43,6 @@ public function getNodeType(): string /** * @param InClassNode $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -65,7 +64,7 @@ public function processNode(Node $node, Scope $scope): array } $errorMessage = $this->createErrorMessage($configFilePath, $className); - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->build()]; } private function resolveRelatedConfigFilePath(string $className): ?string diff --git a/src/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule.php b/src/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule.php index 1c49f584..5813d68f 100644 --- a/src/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule.php +++ b/src/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule.php @@ -10,6 +10,7 @@ use PhpParser\Node\Stmt\Class_; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Rector\VersionBonding\Contract\MinPhpVersionInterface; /** @@ -37,7 +38,6 @@ public function getNodeType(): string /** * @param Class_ $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -64,6 +64,6 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [sprintf(self::ERROR_MESSAGE, $className)]; + return [RuleErrorBuilder::message(sprintf(self::ERROR_MESSAGE, $className))->build()]; } } diff --git a/src/Rules/Rector/RequireAssertConfigureValueObjectRectorRule.php b/src/Rules/Rector/RequireAssertConfigureValueObjectRectorRule.php index 57905363..4027b350 100644 --- a/src/Rules/Rector/RequireAssertConfigureValueObjectRectorRule.php +++ b/src/Rules/Rector/RequireAssertConfigureValueObjectRectorRule.php @@ -15,6 +15,7 @@ use PHPStan\Reflection\FunctionVariantWithPhpDocs; use PHPStan\Reflection\Php\PhpMethodReflection; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\ArrayType; use PHPStan\Type\TypeWithClassName; use Webmozart\Assert\Assert; @@ -45,7 +46,6 @@ public function getNodeType(): string /** * @param ClassMethod $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -66,7 +66,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } private function hasAssertAllIsAOfStaticCall(ClassMethod $classMethod): bool @@ -102,16 +102,16 @@ private function hasArrayObjectTypeParam(ClassMethod $classMethod, ClassReflecti return false; } - foreach ($extendedMethodReflection->getVariants() as $parametersAcceptorWithPhpDoc) { - if (! $parametersAcceptorWithPhpDoc instanceof FunctionVariantWithPhpDocs) { + foreach ($extendedMethodReflection->getVariants() as $variant) { + if (! $variant instanceof FunctionVariantWithPhpDocs) { continue; } - if ($parametersAcceptorWithPhpDoc->getParameters() === []) { + if ($variant->getParameters() === []) { continue; } - $configurationParameterReflection = $parametersAcceptorWithPhpDoc->getParameters()[0]; + $configurationParameterReflection = $variant->getParameters()[0]; $phpDocType = $configurationParameterReflection->getPhpDocType(); if (! $phpDocType instanceof ArrayType) { continue; diff --git a/src/Rules/RegexSuffixInRegexConstantRule.php b/src/Rules/RegexSuffixInRegexConstantRule.php index 1f57440d..84a67583 100644 --- a/src/Rules/RegexSuffixInRegexConstantRule.php +++ b/src/Rules/RegexSuffixInRegexConstantRule.php @@ -12,6 +12,8 @@ use PhpParser\Node\Expr\StaticCall; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleError; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\PHPStanRules\NodeAnalyzer\RegexFuncCallAnalyzer; use Symplify\PHPStanRules\NodeAnalyzer\RegexStaticCallAnalyzer; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; @@ -19,6 +21,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\RegexSuffixInRegexConstantRule\RegexSuffixInRegexConstantRuleTest */ final class RegexSuffixInRegexConstantRule implements Rule, DocumentedRuleInterface @@ -34,17 +37,13 @@ public function __construct( ) { } - /** - * @return class-string - */ public function getNodeType(): string { return CallLike::class; } /** - * @param Expr\CallLike $node - * @return mixed[]|string[] + * @param CallLike $node */ public function processNode(Node $node, Scope $scope): array { @@ -91,7 +90,7 @@ public function run($value) } /** - * @return string[] + * @return list */ private function processConstantName(Expr $expr): array { @@ -109,11 +108,11 @@ private function processConstantName(Expr $expr): array } $errorMessage = sprintf(self::ERROR_MESSAGE, $constantName); - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->build()]; } /** - * @return string[] + * @return list */ private function processStaticCall(StaticCall $staticCall): array { @@ -126,7 +125,7 @@ private function processStaticCall(StaticCall $staticCall): array } /** - * @return string[] + * @return list */ private function processFuncCall(FuncCall $funcCall): array { diff --git a/src/Rules/RequireAttributeNameRule.php b/src/Rules/RequireAttributeNameRule.php index 06943c8b..7c22a0bc 100644 --- a/src/Rules/RequireAttributeNameRule.php +++ b/src/Rules/RequireAttributeNameRule.php @@ -10,7 +10,6 @@ use PhpParser\Node\Identifier; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; -use PHPStan\Rules\RuleError; use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -65,7 +64,6 @@ public function someAction() /** * @param AttributeGroup $node - * @return RuleError[] */ public function processNode(Node $node, Scope $scope): array { diff --git a/src/Rules/SeeAnnotationToTestRule.php b/src/Rules/SeeAnnotationToTestRule.php index 19c1dd3b..e26dabee 100644 --- a/src/Rules/SeeAnnotationToTestRule.php +++ b/src/Rules/SeeAnnotationToTestRule.php @@ -14,6 +14,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\Reflection\ClassReflection; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use PHPUnit\Framework\TestCase; use Symplify\PHPStanRules\PhpDoc\PhpDocResolver; use Symplify\PHPStanRules\PhpDoc\SeePhpDocTagNodesFinder; @@ -23,6 +24,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\SeeAnnotationToTestRule\SeeAnnotationToTestRuleTest */ final class SeeAnnotationToTestRule implements Rule, DocumentedRuleInterface, ConfigurableRuleInterface @@ -42,9 +44,6 @@ public function __construct( ) { } - /** - * @return class-string - */ public function getNodeType(): string { return InClassNode::class; @@ -52,7 +51,6 @@ public function getNodeType(): string /** * @param InClassNode $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -69,7 +67,7 @@ public function processNode(Node $node, Scope $scope): array $docComment = $node->getDocComment(); $errorMessage = sprintf(self::ERROR_MESSAGE, $classReflection->getName()); if (! $docComment instanceof Doc) { - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->build()]; } $resolvedPhpDocBlock = $this->phpDocResolver->resolve($scope, $classReflection, $docComment); @@ -85,7 +83,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/UppercaseConstantRule.php b/src/Rules/UppercaseConstantRule.php index cf885671..dec22f38 100644 --- a/src/Rules/UppercaseConstantRule.php +++ b/src/Rules/UppercaseConstantRule.php @@ -8,11 +8,13 @@ use PhpParser\Node\Stmt\ClassConst; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleErrorBuilder; use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\UppercaseConstantRule\UppercaseConstantRuleTest */ final class UppercaseConstantRule implements Rule, DocumentedRuleInterface @@ -22,9 +24,6 @@ final class UppercaseConstantRule implements Rule, DocumentedRuleInterface */ public const ERROR_MESSAGE = 'Constant "%s" must be uppercase'; - /** - * @return class-string - */ public function getNodeType(): string { return ClassConst::class; @@ -32,7 +31,6 @@ public function getNodeType(): string /** * @param ClassConst $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -43,7 +41,7 @@ public function processNode(Node $node, Scope $scope): array } $errorMessage = sprintf(self::ERROR_MESSAGE, $constantName); - return [$errorMessage]; + return [RuleErrorBuilder::message($errorMessage)->build()]; } return []; diff --git a/tests/Rules/ForbiddenNodeRule/config/configured_rule.neon b/tests/Rules/ForbiddenNodeRule/config/configured_rule.neon index ea9c437a..91fa6fd1 100644 --- a/tests/Rules/ForbiddenNodeRule/config/configured_rule.neon +++ b/tests/Rules/ForbiddenNodeRule/config/configured_rule.neon @@ -10,3 +10,5 @@ services: - PhpParser\Node\Expr\Empty_ - PhpParser\Node\Stmt\Switch_ - PhpParser\Node\Expr\ErrorSuppress + - + class: PhpParser\PrettyPrinter\Standard diff --git a/tests/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule/PhpUpgradeDowngradeRegisteredInSetRuleTest.php b/tests/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule/PhpUpgradeDowngradeRegisteredInSetRuleTest.php index 0c56a851..b0f1be7f 100644 --- a/tests/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule/PhpUpgradeDowngradeRegisteredInSetRuleTest.php +++ b/tests/Rules/Rector/PhpUpgradeDowngradeRegisteredInSetRule/PhpUpgradeDowngradeRegisteredInSetRuleTest.php @@ -4,6 +4,7 @@ namespace Symplify\PHPStanRules\Tests\Rules\Rector\PhpUpgradeDowngradeRegisteredInSetRule; +use Rector\Contract\Rector\RectorInterface; use Iterator; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; @@ -20,6 +21,10 @@ final class PhpUpgradeDowngradeRegisteredInSetRuleTest extends RuleTestCase #[DataProvider('provideData')] public function testRule(string $filePath, array $expectedErrorsWithLines): void { + if (! class_exists(RectorInterface::class)) { + $this->markTestIncomplete('Skip this test because Rector is not installed'); + } + $this->analyse([$filePath], $expectedErrorsWithLines); } diff --git a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/RequireAssertConfigureValueObjectRectorRuleTest.php b/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/RequireAssertConfigureValueObjectRectorRuleTest.php index 6c69e57d..12bfee2e 100644 --- a/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/RequireAssertConfigureValueObjectRectorRuleTest.php +++ b/tests/Rules/Rector/RequireAssertConfigureValueObjectRectorRule/RequireAssertConfigureValueObjectRectorRuleTest.php @@ -9,6 +9,7 @@ use PHPStan\Testing\RuleTestCase; use PHPUnit\Framework\Attributes\DataProvider; use Symplify\PHPStanRules\Rules\Rector\RequireAssertConfigureValueObjectRectorRule; +use function class_exists; final class RequireAssertConfigureValueObjectRectorRuleTest extends RuleTestCase { @@ -18,6 +19,10 @@ final class RequireAssertConfigureValueObjectRectorRuleTest extends RuleTestCase #[DataProvider('provideData')] public function testRule(string $filePath, array $expectedErrorsWithLines): void { + if (! class_exists('Rector\Contract\Rector\ConfigurableRectorInterface')) { + $this->markTestIncomplete('Skip this test because Rector is not installed'); + } + $this->analyse([$filePath], $expectedErrorsWithLines); }