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/AnnotateRegexClassConstWithRegexLinkRule.php b/src/Rules/AnnotateRegexClassConstWithRegexLinkRule.php index 7b6b3582..ed1648db 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 @@ -39,10 +41,6 @@ public function getNodeType(): string return ClassConst::class; } - /** - * @param ClassConst $node - * @return string[] - */ public function processNode(Node $node, Scope $scope): array { if (count($node->consts) !== 1) { @@ -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..21369f1b 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 @@ -47,10 +49,6 @@ public function getNodeType(): string return ClassLike::class; } - /** - * @param ClassLike $node - * @return string[] - */ public function processNode(Node $node, Scope $scope): array { if ($this->autoloadPsr4Paths === []) { @@ -87,7 +85,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)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php b/src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php index c84e3424..d7566e91 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; @@ -38,10 +39,6 @@ public function getNodeType(): string return Interface_::class; } - /** - * @param Interface_ $node - * @return string[] - */ public function processNode(Node $node, Scope $scope): array { $namespace = $scope->getNamespace(); @@ -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..c2207e7e 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; @@ -72,7 +74,6 @@ public function getNodeType(): string /** * @param InClassNode $node - * @return string[] */ public function processNode(Node $node, Scope $scope): array { @@ -117,7 +118,7 @@ class SomeCommand extends Command } /** - * @return array + * @return list */ private function processClassNameAndShort(ClassReflection $classReflection): array { @@ -132,7 +133,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/ForbiddenExtendOfNonAbstractClassRule.php b/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php index 20c622f8..d35a9392 100644 --- a/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php +++ b/src/Rules/ForbiddenExtendOfNonAbstractClassRule.php @@ -14,6 +14,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @implements Rule * @see \Symplify\PHPStanRules\Tests\Rules\ForbiddenExtendOfNonAbstractClassRule\ForbiddenExtendOfNonAbstractClassRuleTest */ final class ForbiddenExtendOfNonAbstractClassRule implements Rule, DocumentedRuleInterface @@ -31,10 +32,6 @@ public function getNodeType(): string return InClassNode::class; } - /** - * @param InClassNode $node - * @return string[] - */ public function processNode(Node $node, Scope $scope): array { $classReflection = $node->getClassReflection(); @@ -63,7 +60,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - return [self::ERROR_MESSAGE]; + return [RuleNodeBuilder::message(self::ERROR_MESSAGE)->build()]; } public function getRuleDefinition(): RuleDefinition diff --git a/src/Rules/NoGlobalConstRule.php b/src/Rules/NoGlobalConstRule.php index 043f56d9..b9f21cb5 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; @@ -28,12 +29,9 @@ public function getNodeType(): string return Const_::class; } - /** - * @param Const_ $node - */ public function processNode(Node $node, Scope $scope): array { - return [self::ERROR_MESSAGE]; + return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()]; } public function getRuleDefinition(): RuleDefinition