Skip to content

Commit

Permalink
[Core] Remove manual reindex stmt_key on ChangedNodeScopeRefresher::r…
Browse files Browse the repository at this point in the history
…eIndexNodeAttributes() (#4109)

* [Core] Remove manual reindex stmt_key on ChangedNodeScopeRefresher::reIndexNodeAttributes()

* array_values() before reindex

* clean up
  • Loading branch information
samsonasik committed Jun 7, 2023
1 parent 63816c0 commit 2449c45
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 0 additions & 21 deletions src/Application/ChangedNodeScopeRefresher.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@
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_;
use PhpParser\Node\Stmt\Property;
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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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[]
*/
Expand Down

0 comments on commit 2449c45

Please sign in to comment.