Skip to content

Commit

Permalink
[Core] Improve RectifiedAnalyzer: no need to check created by rule wh…
Browse files Browse the repository at this point in the history
…en original Node is null (#3014)
  • Loading branch information
samsonasik committed Oct 25, 2022
1 parent a59fd48 commit d82ef17
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 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, $node, $originalNode)) {
if ($this->hasCreatedByRule($rectorClass, $originalNode)) {
return new RectifiedNode($rectorClass, $node);
}

Expand All @@ -62,9 +62,12 @@ public function verify(string $rectorClass, Node $node, string $filePath): ?Rect
/**
* @param class-string<RectorInterface> $rectorClass
*/
private function hasCreatedByRule(string $rectorClass, Node $node, ?Node $originalNode): bool
private function hasCreatedByRule(string $rectorClass, ?Node $originalNode): bool
{
$originalNode ??= $node;
if (! $originalNode instanceof Node) {
return false;
}

$createdByRule = $originalNode->getAttribute(AttributeKey::CREATED_BY_RULE) ?? [];
return in_array($rectorClass, $createdByRule, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class Fixture
*/
public function run($a = '"', $b)
{
if ($a === '' || $a === '0') {
if ($a === '') {
return;
}
if ($a === '0') {
return;
}
if (! $b) {
Expand Down

0 comments on commit d82ef17

Please sign in to comment.