diff --git a/packages/Php/src/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php b/packages/Php/src/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php index 432d2d9023c..492ecf6b22a 100644 --- a/packages/Php/src/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php +++ b/packages/Php/src/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php @@ -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; } @@ -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; + } }