Skip to content

Commit ac00ca3

Browse files
committed
[stmts-aware] Use NodeGroup::STMTS_AWARE over StmtsAwareInterface
1 parent dd62a5e commit ac00ca3

File tree

9 files changed

+32
-23
lines changed

9 files changed

+32
-23
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"phpstan/phpstan": "^2.1.32",
1212
"phpstan/phpstan-webmozart-assert": "^2.0",
1313
"phpunit/phpunit": "^11.5",
14-
"rector/rector-src": "dev-main",
14+
"rector/rector-src": "dev-tv-stmts-interface",
1515
"symplify/easy-coding-standard": "^12.3",
1616
"symplify/rule-doc-generator": "^12.2",
1717
"symplify/vendor-patches": "^11.5",

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ parameters:
88

99
reportUnmatchedIgnoredErrors: false
1010

11+
# see https://phpstan.org/writing-php-code/phpdoc-types#global-type-aliases
12+
typeAliases:
13+
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_
14+
1115
# requires exact closure types
1216
checkMissingCallableSignature: true
1317

rules/DowngradePhp72/Rector/FuncCall/DowngradeStreamIsattyRector.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
use PhpParser\Node\Stmt\Return_;
1515
use PhpParser\Node\Stmt\Switch_;
1616
use PHPStan\Analyser\Scope;
17-
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
1817
use Rector\Exception\ShouldNotHappenException;
1918
use Rector\Naming\Naming\VariableNaming;
2019
use Rector\NodeAnalyzer\ExprInTopStmtMatcher;
2120
use Rector\NodeTypeResolver\Node\AttributeKey;
21+
use Rector\PhpParser\Enum\NodeGroup;
2222
use Rector\PhpParser\Parser\InlineCodeParser;
2323
use Rector\PHPStan\ScopeFetcher;
2424
use Rector\Rector\AbstractRector;
@@ -93,11 +93,12 @@ public function run($stream)
9393
*/
9494
public function getNodeTypes(): array
9595
{
96-
return [StmtsAwareInterface::class, Switch_::class, Return_::class, Expression::class, Echo_::class];
96+
$stmtsAware = NodeGroup::STMTS_AWARE;
97+
return [...$stmtsAware, Switch_::class, Return_::class, Expression::class, Echo_::class];
9798
}
9899

99100
/**
100-
* @param StmtsAwareInterface|Switch_|Return_|Expression|Echo_ $node
101+
* @param StmtsAware|Switch_|Return_|Expression|Echo_ $node
101102
* @return Node[]|null
102103
*/
103104
public function refactor(Node $node): ?array

rules/DowngradePhp73/Rector/FuncCall/DowngradeArrayKeyFirstLastRector.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Rector\Naming\Naming\VariableNaming;
3030
use Rector\NodeAnalyzer\ExprInTopStmtMatcher;
3131
use Rector\NodeTypeResolver\Node\AttributeKey;
32+
use Rector\PhpParser\Enum\NodeGroup;
3233
use Rector\Rector\AbstractRector;
3334
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
3435
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -80,11 +81,12 @@ public function run($items)
8081
*/
8182
public function getNodeTypes(): array
8283
{
83-
return [StmtsAwareInterface::class, Switch_::class, Return_::class, Expression::class, Echo_::class];
84+
$stmtsAware = NodeGroup::STMTS_AWARE;
85+
return [...$stmtsAware, Switch_::class, Return_::class, Expression::class, Echo_::class];
8486
}
8587

8688
/**
87-
* @param StmtsAwareInterface|Switch_|Return_|Expression|Echo_ $node
89+
* @param StmtsAware|Switch_|Return_|Expression|Echo_ $node
8890
* @return Node[]|null
8991
*/
9092
public function refactor(Node $node): ?array
@@ -143,7 +145,7 @@ private function resolveVariableFromCallLikeScope(CallLike $callLike, ?Scope $sc
143145
*/
144146
private function refactorArrayKeyFirst(
145147
FuncCall $funcCall,
146-
StmtsAwareInterface|Switch_|Return_|Expression|Echo_ $stmt
148+
Node|Switch_|Return_|Expression|Echo_ $stmt
147149
): null|array {
148150
$args = $funcCall->getArgs();
149151
if (! isset($args[0])) {
@@ -182,7 +184,7 @@ private function refactorArrayKeyFirst(
182184
*/
183185
private function refactorArrayKeyLast(
184186
FuncCall $funcCall,
185-
StmtsAwareInterface|Switch_|Return_|Expression|Echo_ $stmt
187+
Node|Switch_|Return_|Expression|Echo_ $stmt
186188
): null|array {
187189
$args = $funcCall->getArgs();
188190
$firstArg = $args[0] ?? null;

rules/DowngradePhp81/Rector/FuncCall/DowngradeArrayIsListRector.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
use PhpParser\Node\Stmt\Return_;
1616
use PhpParser\Node\Stmt\Switch_;
1717
use PHPStan\Analyser\Scope;
18-
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
1918
use Rector\Exception\ShouldNotHappenException;
2019
use Rector\NodeAnalyzer\ExprInTopStmtMatcher;
2120
use Rector\NodeTypeResolver\Node\AttributeKey;
21+
use Rector\PhpParser\Enum\NodeGroup;
2222
use Rector\PhpParser\Parser\InlineCodeParser;
2323
use Rector\Rector\AbstractRector;
2424
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -78,11 +78,12 @@ public function getRuleDefinition(): RuleDefinition
7878
*/
7979
public function getNodeTypes(): array
8080
{
81-
return [StmtsAwareInterface::class, Switch_::class, Return_::class, Expression::class, Echo_::class];
81+
$stmtsAware = NodeGroup::STMTS_AWARE;
82+
return [...$stmtsAware, Switch_::class, Return_::class, Expression::class, Echo_::class];
8283
}
8384

8485
/**
85-
* @param StmtsAwareInterface|Switch_|Return_|Expression|Echo_ $node
86+
* @param StmtsAware|Switch_|Return_|Expression|Echo_ $node
8687
* @return Node[]|null
8788
*/
8889
public function refactor(Node $node): ?array

rules/DowngradePhp81/Rector/StmtsAwareInterface/DowngradeSetAccessibleReflectionPropertyRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use PhpParser\Node\Stmt\Return_;
2121
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
2222
use Rector\Naming\Naming\VariableNaming;
23+
use Rector\PhpParser\Enum\NodeGroup;
2324
use Rector\PHPStan\ScopeFetcher;
2425
use Rector\Rector\AbstractRector;
2526
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -81,7 +82,7 @@ public function run($object)
8182
*/
8283
public function getNodeTypes(): array
8384
{
84-
return [StmtsAwareInterface::class];
85+
return NodeGroup::STMTS_AWARE;
8586
}
8687

8788
/**

rules/DowngradePhp83/Rector/FuncCall/DowngradeJsonValidateRector.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
use PhpParser\Node\Stmt\Return_;
1616
use PhpParser\Node\Stmt\Switch_;
1717
use PHPStan\Analyser\Scope;
18-
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
1918
use Rector\Exception\ShouldNotHappenException;
2019
use Rector\Naming\Naming\VariableNaming;
2120
use Rector\NodeAnalyzer\ExprInTopStmtMatcher;
2221
use Rector\NodeTypeResolver\Node\AttributeKey;
22+
use Rector\PhpParser\Enum\NodeGroup;
2323
use Rector\PhpParser\Parser\InlineCodeParser;
2424
use Rector\PHPStan\ScopeFetcher;
2525
use Rector\Rector\AbstractRector;
@@ -84,11 +84,12 @@ public function getRuleDefinition(): RuleDefinition
8484
*/
8585
public function getNodeTypes(): array
8686
{
87-
return [StmtsAwareInterface::class, Switch_::class, Return_::class, Expression::class, Echo_::class];
87+
$stmtsAware = NodeGroup::STMTS_AWARE;
88+
return [...$stmtsAware, Switch_::class, Return_::class, Expression::class, Echo_::class];
8889
}
8990

9091
/**
91-
* @param StmtsAwareInterface|Switch_|Return_|Expression|Echo_ $node
92+
* @param StmtsAware|Switch_|Return_|Expression|Echo_ $node
9293
* @return Node[]|null
9394
*/
9495
public function refactor(Node $node): ?array

rules/DowngradePhp85/Rector/StmtsAwareInterface/DowngradePipeOperatorRector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use PhpParser\Node\Expr\StaticCall;
1515
use PhpParser\Node\Expr\Variable;
1616
use PhpParser\Node\Stmt\Expression;
17-
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
1817
use Rector\NodeFactory\NamedVariableFactory;
18+
use Rector\PhpParser\Enum\NodeGroup;
1919
use Rector\Rector\AbstractRector;
2020
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2121
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -67,11 +67,11 @@ public function getRuleDefinition(): RuleDefinition
6767

6868
public function getNodeTypes(): array
6969
{
70-
return [StmtsAwareInterface::class];
70+
return NodeGroup::STMTS_AWARE;
7171
}
7272

7373
/**
74-
* @param StmtsAwareInterface $node
74+
* @param StmtsAware $node
7575
*/
7676
public function refactor(Node $node): ?Node
7777
{

src/NodeAnalyzer/ExprInTopStmtMatcher.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use PhpParser\Node\Stmt\Switch_;
1818
use PhpParser\Node\Stmt\While_;
1919
use PHPStan\Analyser\Scope;
20-
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
2120
use Rector\NodeTypeResolver\Node\AttributeKey;
2221
use Rector\PhpParser\Node\BetterNodeFinder;
2322

@@ -35,7 +34,7 @@ public function __construct(
3534
/**
3635
* @param callable(Node $node): bool $filter
3736
*/
38-
public function match(StmtsAwareInterface|Switch_|Return_|Expression|Echo_ $stmt, callable $filter): null|Expr
37+
public function match(Node|Switch_|Return_|Expression|Echo_ $stmt, callable $filter): null|Expr
3938
{
4039
if ($stmt instanceof Closure) {
4140
return null;
@@ -80,7 +79,7 @@ public function match(StmtsAwareInterface|Switch_|Return_|Expression|Echo_ $stmt
8079
* @param callable(Node $node): bool $filter
8180
*/
8281
private function resolveOnReturnOrExpression(
83-
StmtsAwareInterface|Switch_|Return_|Expression|Echo_ $stmt,
82+
Node|Switch_|Return_|Expression|Echo_ $stmt,
8483
callable $filter
8584
): ?Expr {
8685
if (! $stmt instanceof Return_ && ! $stmt instanceof Expression) {
@@ -99,7 +98,7 @@ private function resolveOnReturnOrExpression(
9998
* @param callable(Node $node): bool $filter
10099
*/
101100
private function resolveExpr(
102-
StmtsAwareInterface|Switch_|Return_|Expression|Echo_ $stmt,
101+
Node|Switch_|Return_|Expression|Echo_ $stmt,
103102
array|Expr $exprs,
104103
callable $filter
105104
): ?Expr {
@@ -127,7 +126,7 @@ private function resolveExpr(
127126
* @param callable(Node $node): bool $filter
128127
*/
129128
private function resolveFromChildCond(
130-
StmtsAwareInterface|Switch_|Return_|Expression|Echo_ $stmt,
129+
Node|Switch_|Return_|Expression|Echo_ $stmt,
131130
callable $filter
132131
): null|Expr {
133132
if (! $stmt instanceof If_ && ! $stmt instanceof Switch_) {

0 commit comments

Comments
 (0)