|
14 | 14 | use PhpParser\Node\Expr\StaticCall; |
15 | 15 | use PhpParser\Node\FunctionLike; |
16 | 16 | use PhpParser\Node\MatchArm; |
| 17 | +use PhpParser\Node\Stmt\ClassLike; |
17 | 18 | use PhpParser\Node\Stmt\ClassMethod; |
| 19 | +use PhpParser\Node\Stmt\Declare_; |
18 | 20 | use PhpParser\Node\Stmt\Function_; |
19 | 21 | use PhpParser\Node\Stmt\If_; |
20 | 22 | use PhpParser\Node\Stmt\Switch_; |
21 | 23 | use PhpParser\Node\Stmt\TryCatch; |
| 24 | +use Rector\Contract\PhpParser\Node\StmtsAwareInterface; |
22 | 25 |
|
23 | 26 | final class NodeAttributeReIndexer |
24 | 27 | { |
25 | 28 | public static function reIndexNodeAttributes(Node $node): ?Node |
26 | 29 | { |
27 | | - if ($node instanceof FunctionLike) { |
28 | | - /** @var ClassMethod|Function_|Closure $node */ |
29 | | - $node->params = array_values($node->params); |
| 30 | + if (($node instanceof StmtsAwareInterface || $node instanceof ClassLike || $node instanceof Declare_) && $node->stmts !== null) { |
| 31 | + $node->stmts = array_values($node->stmts); |
30 | 32 |
|
31 | | - if ($node instanceof Closure) { |
32 | | - $node->uses = array_values($node->uses); |
| 33 | + if ($node instanceof If_) { |
| 34 | + $node->elseifs = array_values($node->elseifs); |
| 35 | + return $node; |
33 | 36 | } |
| 37 | + |
| 38 | + if ($node instanceof TryCatch) { |
| 39 | + $node->catches = array_values($node->catches); |
| 40 | + return $node; |
| 41 | + } |
| 42 | + |
| 43 | + return $node; |
34 | 44 | } |
35 | 45 |
|
36 | 46 | if ($node instanceof CallLike) { |
37 | 47 | /** @var FuncCall|MethodCall|New_|NullsafeMethodCall|StaticCall $node */ |
38 | 48 | $node->args = array_values($node->args); |
| 49 | + return $node; |
39 | 50 | } |
40 | 51 |
|
41 | | - if ($node instanceof If_) { |
42 | | - $node->elseifs = array_values($node->elseifs); |
43 | | - } |
| 52 | + if ($node instanceof FunctionLike) { |
| 53 | + /** @var ClassMethod|Function_|Closure $node */ |
| 54 | + $node->params = array_values($node->params); |
| 55 | + |
| 56 | + if ($node instanceof Closure) { |
| 57 | + $node->uses = array_values($node->uses); |
| 58 | + } |
44 | 59 |
|
45 | | - if ($node instanceof TryCatch) { |
46 | | - $node->catches = array_values($node->catches); |
| 60 | + return $node; |
47 | 61 | } |
48 | 62 |
|
49 | 63 | if ($node instanceof Switch_) { |
50 | 64 | $node->cases = array_values($node->cases); |
| 65 | + return $node; |
51 | 66 | } |
52 | 67 |
|
53 | 68 | if ($node instanceof MatchArm && is_array($node->conds)) { |
|
0 commit comments