diff --git a/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/StmtKeyNodeVisitor.php b/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/StmtKeyNodeVisitor.php index 912b1df6860..ceaa956de0f 100644 --- a/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/StmtKeyNodeVisitor.php +++ b/packages/NodeTypeResolver/PHPStan/Scope/NodeVisitor/StmtKeyNodeVisitor.php @@ -53,6 +53,8 @@ public function enterNode(Node $node): ?Node return null; } + $node->stmts = array_values($node->stmts); + // re-index stmt key under current node foreach ($node->stmts as $key => $childStmt) { $childStmt->setAttribute(AttributeKey::STMT_KEY, $key); diff --git a/src/Application/ChangedNodeScopeRefresher.php b/src/Application/ChangedNodeScopeRefresher.php index 4627a19819b..47d558c2955 100644 --- a/src/Application/ChangedNodeScopeRefresher.php +++ b/src/Application/ChangedNodeScopeRefresher.php @@ -17,9 +17,7 @@ use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\FunctionLike; use PhpParser\Node\Stmt; -use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; -use PhpParser\Node\Stmt\Declare_; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\If_; @@ -27,7 +25,6 @@ use PhpParser\Node\Stmt\Switch_; use PhpParser\Node\Stmt\TryCatch; use PHPStan\Analyser\MutatingScope; -use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\NodeAnalyzer\ScopeAnalyzer; use Rector\Core\Provider\CurrentFileProvider; @@ -98,19 +95,6 @@ public function refresh(Node $node, ?MutatingScope $mutatingScope, ?string $file public function reIndexNodeAttributes(Node $node): void { - if ($this->hasArrayStmtsNode($node)) { - /** - * @var StmtsAwareInterface|ClassLike|Declare_ $node - * @var Stmt[] $stmts - */ - $stmts = $node->stmts; - $node->stmts = array_values($stmts); - - foreach ($node->stmts as $key => $stmt) { - $stmt->setAttribute(AttributeKey::STMT_KEY, $key); - } - } - if ($node instanceof FunctionLike) { /** @var ClassMethod|Function_|Closure $node */ $node->params = array_values($node->params); @@ -138,11 +122,6 @@ public function reIndexNodeAttributes(Node $node): void } } - private function hasArrayStmtsNode(Node $node): bool - { - return ($node instanceof ClassLike || $node instanceof StmtsAwareInterface || $node instanceof Declare_) && $node->stmts !== null; - } - /** * @return Stmt[] */