Skip to content

Commit

Permalink
[PHP] Fix AddDefaultValueForUndefinedVariableRector for static variab…
Browse files Browse the repository at this point in the history
…le (#1509)

[PHP] Fix AddDefaultValueForUndefinedVariableRector for static variable
  • Loading branch information
TomasVotruba authored May 30, 2019
2 parents bcd3ef6 + cad5bb2 commit deea2a9
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function refactor(Node $node): ?Node
}

$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof Assign) {
if ($parentNode instanceof Assign || $this->isStaticVariable($parentNode)) {
return null;
}

Expand Down Expand Up @@ -138,4 +138,17 @@ public function refactor(Node $node): ?Node

return $node;
}

private function isStaticVariable(Node $parentNode): bool
{
// definition of static variable
if ($parentNode instanceof Node\Stmt\StaticVar) {
$parentParentNode = $parentNode->getAttribute(AttributeKey::PARENT_NODE);
if ($parentParentNode instanceof Node\Stmt\Static_) {
return true;
}
}

return false;
}
}

0 comments on commit deea2a9

Please sign in to comment.