diff --git a/composer.json b/composer.json index 606ebf49d..742287669 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "phpstan/phpstan-webmozart-assert": "^2.0", "phpunit/phpunit": "^11.5", "rector/jack": "^0.2.9", - "rector/rector-src": "dev-main", + "rector/rector-src": "dev-tv-stmts-interface", "rector/type-perfect": "^2.1", "symfony/config": "^6.4", "symfony/dependency-injection": "^6.4", diff --git a/phpstan.neon b/phpstan.neon index 0e6dc7bb4..abf83d107 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,7 +5,11 @@ parameters: level: 8 errorFormat: symplify - # reportUnmatchedIgnoredErrors: false + # see https://phpstan.org/writing-php-code/phpdoc-types#global-type-aliases + typeAliases: + StmtsAware: \PhpParser\Node\Expr\Closure | \PhpParser\Node\Stmt\Case_ | \PhpParser\Node\Stmt\Catch_ | \PhpParser\Node\Stmt\ClassMethod | \PhpParser\Node\Stmt\Do_ | \PhpParser\Node\Stmt\Else_ | \PhpParser\Node\Stmt\ElseIf_ | \PhpParser\Node\Stmt\Finally_ | \PhpParser\Node\Stmt\For_ | \PhpParser\Node\Stmt\Foreach_ | \PhpParser\Node\Stmt\Function_ | \PhpParser\Node\Stmt\If_ | \PhpParser\Node\Stmt\Namespace_ | \PhpParser\Node\Stmt\TryCatch | \PhpParser\Node\Stmt\While_ + + reportUnmatchedIgnoredErrors: false treatPhpDocTypesAsCertain: false paths: @@ -59,3 +63,6 @@ parameters: - rules/Configs/NodeDecorator/ServiceDefaultsCallClosureDecorator.php - '#Parameter 1 should use "PHPStan\\BetterReflection\\Reflection\\Adapter\\ReflectionMethod" type as the only type passed to this method#' + + # local use php 8.3 + - identifier: typeCoverage.constantTypeCoverage \ No newline at end of file diff --git a/rules/CodeQuality/Rector/ClassMethod/TemplateAnnotationToThisRenderRector.php b/rules/CodeQuality/Rector/ClassMethod/TemplateAnnotationToThisRenderRector.php index 0de660aed..4fcaa3879 100644 --- a/rules/CodeQuality/Rector/ClassMethod/TemplateAnnotationToThisRenderRector.php +++ b/rules/CodeQuality/Rector/ClassMethod/TemplateAnnotationToThisRenderRector.php @@ -199,7 +199,7 @@ private function refactorClassMethod( return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } - if (! $node instanceof StmtsAwareInterface) { + if (! property_exists($node, 'stmts')) { return null; } diff --git a/rules/CodeQuality/Rector/Class_/InlineClassRoutePrefixRector.php b/rules/CodeQuality/Rector/Class_/InlineClassRoutePrefixRector.php index 0baa479ec..d26548184 100644 --- a/rules/CodeQuality/Rector/Class_/InlineClassRoutePrefixRector.php +++ b/rules/CodeQuality/Rector/Class_/InlineClassRoutePrefixRector.php @@ -8,6 +8,7 @@ use PhpParser\Node\Attribute; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode; use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode; use Rector\BetterPhpDocParser\PhpDoc\StringNode; @@ -257,10 +258,9 @@ public function refactor(Node $node): ?Class_ return $node; } - private function shouldSkipMethod(Node\Stmt\ClassMethod $classMethod): bool + private function shouldSkipMethod(ClassMethod $classMethod): bool { - return - !$classMethod->isPublic() + return ! $classMethod->isPublic() || $this->magicClassMethodAnalyzer->isUnsafeOverridden($classMethod); } diff --git a/rules/Symfony42/Rector/New_/RootNodeTreeBuilderRector.php b/rules/Symfony42/Rector/New_/RootNodeTreeBuilderRector.php index c6d3abe56..9bcd4eaed 100644 --- a/rules/Symfony42/Rector/New_/RootNodeTreeBuilderRector.php +++ b/rules/Symfony42/Rector/New_/RootNodeTreeBuilderRector.php @@ -13,6 +13,7 @@ use PhpParser\Node\Stmt\Expression; use PHPStan\Type\ObjectType; use Rector\Contract\PhpParser\Node\StmtsAwareInterface; +use Rector\PhpParser\Enum\NodeGroup; use Rector\PhpParser\Node\BetterNodeFinder; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -61,11 +62,11 @@ public function getRuleDefinition(): RuleDefinition */ public function getNodeTypes(): array { - return [StmtsAwareInterface::class]; + return NodeGroup::STMTS_AWARE; } /** - * @param StmtsAwareInterface $node + * @param StmtsAware $node */ public function refactor(Node $node): ?Node { diff --git a/rules/Symfony43/Rector/StmtsAwareInterface/TwigBundleFilesystemLoaderToTwigRector.php b/rules/Symfony43/Rector/StmtsAwareInterface/TwigBundleFilesystemLoaderToTwigRector.php index 5cb907022..ec6a9d0fc 100644 --- a/rules/Symfony43/Rector/StmtsAwareInterface/TwigBundleFilesystemLoaderToTwigRector.php +++ b/rules/Symfony43/Rector/StmtsAwareInterface/TwigBundleFilesystemLoaderToTwigRector.php @@ -13,6 +13,7 @@ use PhpParser\Node\Stmt\Expression; use PHPStan\Type\ObjectType; use Rector\Contract\PhpParser\Node\StmtsAwareInterface; +use Rector\PhpParser\Enum\NodeGroup; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -50,11 +51,11 @@ public function getRuleDefinition(): RuleDefinition */ public function getNodeTypes(): array { - return [StmtsAwareInterface::class]; + return NodeGroup::STMTS_AWARE; } /** - * @param StmtsAwareInterface $node + * @param StmtsAware $node */ public function refactor(Node $node): ?Node { diff --git a/rules/Symfony72/Rector/StmtsAwareInterface/PushRequestToRequestStackConstructorRector.php b/rules/Symfony72/Rector/StmtsAwareInterface/PushRequestToRequestStackConstructorRector.php index 9617164e1..946cf81fb 100644 --- a/rules/Symfony72/Rector/StmtsAwareInterface/PushRequestToRequestStackConstructorRector.php +++ b/rules/Symfony72/Rector/StmtsAwareInterface/PushRequestToRequestStackConstructorRector.php @@ -12,7 +12,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\New_; use PhpParser\Node\Stmt\Expression; -use Rector\Contract\PhpParser\Node\StmtsAwareInterface; +use Rector\PhpParser\Enum\NodeGroup; use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\Rector\AbstractRector; use Rector\Symfony\Enum\SymfonyClass; @@ -69,16 +69,23 @@ public function run() ]); } + /** + * @return array> + */ public function getNodeTypes(): array { - return [StmtsAwareInterface::class]; + return NodeGroup::STMTS_AWARE; } /** - * @param StmtsAwareInterface $node + * @param StmtsAware $node */ - public function refactor(Node $node): ?StmtsAwareInterface + public function refactor(Node $node): ?Node { + if ($node->stmts === null) { + return null; + } + if (! $this->testsNodeAnalyzer->isInTestClass($node)) { return null; }