From ebfb78242931b03c082ce5b2f018b84c6742373f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 20 Dec 2024 12:45:44 +0700 Subject: [PATCH] Reduce double loop to set stmt_key on refresh process (#6619) --- src/Application/ChangedNodeScopeRefresher.php | 4 +++- src/Application/NodeAttributeReIndexer.php | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Application/ChangedNodeScopeRefresher.php b/src/Application/ChangedNodeScopeRefresher.php index 6a85cc6245..51322fba22 100644 --- a/src/Application/ChangedNodeScopeRefresher.php +++ b/src/Application/ChangedNodeScopeRefresher.php @@ -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); diff --git a/src/Application/NodeAttributeReIndexer.php b/src/Application/NodeAttributeReIndexer.php index 9e1c92f8ce..d8dda74d46 100644 --- a/src/Application/NodeAttributeReIndexer.php +++ b/src/Application/NodeAttributeReIndexer.php @@ -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);