Skip to content

Commit

Permalink
Reduce double loop to set stmt_key on refresh process (#6619)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik authored Dec 20, 2024
1 parent a72a021 commit ebfb782
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Application/ChangedNodeScopeRefresher.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public function refresh(Node $node, string $filePath, ?MutatingScope $mutatingSc
throw new ShouldNotHappenException($errorMessage);
}

NodeAttributeReIndexer::reIndexNodeAttributes($node);
// reindex stmt_key already covered on StmtKeyNodeVisitor on next processNodes()
// so set flag $reIndexStmtKey to false to avoid double loop
NodeAttributeReIndexer::reIndexNodeAttributes($node, false);

$stmts = $this->resolveStmts($node);
$this->phpStanNodeScopeResolver->processNodes($stmts, $filePath, $mutatingScope);
Expand Down
6 changes: 4 additions & 2 deletions src/Application/NodeAttributeReIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public static function reIndexStmtKeyNodeAttributes(Node $node): ?Node
return $node;
}

public static function reIndexNodeAttributes(Node $node): ?Node
public static function reIndexNodeAttributes(Node $node, bool $reIndexStmtKey = true): ?Node
{
self::reIndexStmtKeyNodeAttributes($node);
if ($reIndexStmtKey) {
self::reIndexStmtKeyNodeAttributes($node);
}

if ($node instanceof If_) {
$node->elseifs = array_values($node->elseifs);
Expand Down

0 comments on commit ebfb782

Please sign in to comment.