Skip to content

Commit 7271217

Browse files
authored
[stmts-aware] Use NodeGroup::STMTS_AWARE over StmtsAwareInterface (#886)
* [stmts-aware] Use NodeGroup::STMTS_AWARE over StmtsAwareInterface * fix phpstan
1 parent 2e68e2a commit 7271217

7 files changed

Lines changed: 30 additions & 14 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"phpstan/phpstan-webmozart-assert": "^2.0",
1515
"phpunit/phpunit": "^11.5",
1616
"rector/jack": "^0.2.9",
17-
"rector/rector-src": "dev-main",
17+
"rector/rector-src": "dev-tv-stmts-interface",
1818
"rector/type-perfect": "^2.1",
1919
"symfony/config": "^6.4",
2020
"symfony/dependency-injection": "^6.4",

phpstan.neon

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ parameters:
55
level: 8
66
errorFormat: symplify
77

8-
# reportUnmatchedIgnoredErrors: false
8+
# see https://phpstan.org/writing-php-code/phpdoc-types#global-type-aliases
9+
typeAliases:
10+
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_
11+
12+
reportUnmatchedIgnoredErrors: false
913
treatPhpDocTypesAsCertain: false
1014

1115
paths:
@@ -59,3 +63,6 @@ parameters:
5963
- rules/Configs/NodeDecorator/ServiceDefaultsCallClosureDecorator.php
6064

6165
- '#Parameter 1 should use "PHPStan\\BetterReflection\\Reflection\\Adapter\\ReflectionMethod" type as the only type passed to this method#'
66+
67+
# local use php 8.3
68+
- identifier: typeCoverage.constantTypeCoverage

rules/CodeQuality/Rector/ClassMethod/TemplateAnnotationToThisRenderRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private function refactorClassMethod(
199199
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
200200
}
201201

202-
if (! $node instanceof StmtsAwareInterface) {
202+
if (! property_exists($node, 'stmts')) {
203203
return null;
204204
}
205205

rules/CodeQuality/Rector/Class_/InlineClassRoutePrefixRector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpParser\Node\Attribute;
99
use PhpParser\Node\Scalar\String_;
1010
use PhpParser\Node\Stmt\Class_;
11+
use PhpParser\Node\Stmt\ClassMethod;
1112
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
1213
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
1314
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
@@ -257,10 +258,9 @@ public function refactor(Node $node): ?Class_
257258
return $node;
258259
}
259260

260-
private function shouldSkipMethod(Node\Stmt\ClassMethod $classMethod): bool
261+
private function shouldSkipMethod(ClassMethod $classMethod): bool
261262
{
262-
return
263-
!$classMethod->isPublic()
263+
return ! $classMethod->isPublic()
264264
|| $this->magicClassMethodAnalyzer->isUnsafeOverridden($classMethod);
265265
}
266266

rules/Symfony42/Rector/New_/RootNodeTreeBuilderRector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PhpParser\Node\Stmt\Expression;
1414
use PHPStan\Type\ObjectType;
1515
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
16+
use Rector\PhpParser\Enum\NodeGroup;
1617
use Rector\PhpParser\Node\BetterNodeFinder;
1718
use Rector\Rector\AbstractRector;
1819
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -61,11 +62,11 @@ public function getRuleDefinition(): RuleDefinition
6162
*/
6263
public function getNodeTypes(): array
6364
{
64-
return [StmtsAwareInterface::class];
65+
return NodeGroup::STMTS_AWARE;
6566
}
6667

6768
/**
68-
* @param StmtsAwareInterface $node
69+
* @param StmtsAware $node
6970
*/
7071
public function refactor(Node $node): ?Node
7172
{

rules/Symfony43/Rector/StmtsAwareInterface/TwigBundleFilesystemLoaderToTwigRector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PhpParser\Node\Stmt\Expression;
1414
use PHPStan\Type\ObjectType;
1515
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
16+
use Rector\PhpParser\Enum\NodeGroup;
1617
use Rector\Rector\AbstractRector;
1718
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1819
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -50,11 +51,11 @@ public function getRuleDefinition(): RuleDefinition
5051
*/
5152
public function getNodeTypes(): array
5253
{
53-
return [StmtsAwareInterface::class];
54+
return NodeGroup::STMTS_AWARE;
5455
}
5556

5657
/**
57-
* @param StmtsAwareInterface $node
58+
* @param StmtsAware $node
5859
*/
5960
public function refactor(Node $node): ?Node
6061
{

rules/Symfony72/Rector/StmtsAwareInterface/PushRequestToRequestStackConstructorRector.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use PhpParser\Node\Expr\MethodCall;
1313
use PhpParser\Node\Expr\New_;
1414
use PhpParser\Node\Stmt\Expression;
15-
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
15+
use Rector\PhpParser\Enum\NodeGroup;
1616
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
1717
use Rector\Rector\AbstractRector;
1818
use Rector\Symfony\Enum\SymfonyClass;
@@ -69,16 +69,23 @@ public function run()
6969
]);
7070
}
7171

72+
/**
73+
* @return array<class-string<Node>>
74+
*/
7275
public function getNodeTypes(): array
7376
{
74-
return [StmtsAwareInterface::class];
77+
return NodeGroup::STMTS_AWARE;
7578
}
7679

7780
/**
78-
* @param StmtsAwareInterface $node
81+
* @param StmtsAware $node
7982
*/
80-
public function refactor(Node $node): ?StmtsAwareInterface
83+
public function refactor(Node $node): ?Node
8184
{
85+
if ($node->stmts === null) {
86+
return null;
87+
}
88+
8289
if (! $this->testsNodeAnalyzer->isInTestClass($node)) {
8390
return null;
8491
}

0 commit comments

Comments
 (0)