Skip to content

Commit

Permalink
[Core] Improve performance: verify consecutive execute same Rector Ru…
Browse files Browse the repository at this point in the history
…le when Original Node is Null (#3047)
  • Loading branch information
samsonasik committed Nov 11, 2022
1 parent ac8fc4c commit 4d93103
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/ProcessAnalyzer/RectifiedAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function verify(string $rectorClass, Node $node, string $filePath): ?Rect
{
$originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE);

if ($this->hasCreatedByRule($rectorClass, $originalNode)) {
if ($this->hasCreatedByRule($rectorClass, $node, $originalNode)) {
return new RectifiedNode($rectorClass, $node);
}

Expand All @@ -62,10 +62,17 @@ public function verify(string $rectorClass, Node $node, string $filePath): ?Rect
/**
* @param class-string<RectorInterface> $rectorClass
*/
private function hasCreatedByRule(string $rectorClass, ?Node $originalNode): bool
private function hasCreatedByRule(string $rectorClass, Node $node, ?Node $originalNode): bool
{
if (! $originalNode instanceof Node) {
return false;
$createdByRule = $node->getAttribute(AttributeKey::CREATED_BY_RULE) ?? [];
$lastRectorRuleKey = array_key_last($createdByRule);

if ($lastRectorRuleKey === null) {
return false;
}

return $createdByRule[$lastRectorRuleKey] === $rectorClass;
}

$createdByRule = $originalNode->getAttribute(AttributeKey::CREATED_BY_RULE) ?? [];
Expand Down

0 comments on commit 4d93103

Please sign in to comment.