Skip to content

Commit

Permalink
[Core] Improve performance: only reindex Node Attributes when Origina…
Browse files Browse the repository at this point in the history
…l Node is not null (#3043)
  • Loading branch information
samsonasik committed Nov 11, 2022
1 parent b31bb42 commit ac8fc4c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ final public function enterNode(Node $node)

$this->printDebugCurrentFileAndRule();

$this->changedNodeScopeRefresher->reIndexNodeAttributes($node);
$originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE);
if ($originalNode instanceof Node) {
$this->changedNodeScopeRefresher->reIndexNodeAttributes($node);
}

$refactoredNode = $this->refactor($node);

Expand All @@ -220,8 +223,7 @@ final public function enterNode(Node $node)
throw new ShouldNotHappenException($errorMessage);
}

/** @var Node $originalNode */
$originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE) ?? $node;
$originalNode ??= $node;

/** @var Node[]|Node $refactoredNode */
$this->createdByRuleDecorator->decorate($refactoredNode, $originalNode, static::class);
Expand Down

0 comments on commit ac8fc4c

Please sign in to comment.