diff --git a/packages/Laravel/src/Rector/FuncCall/HelperFunctionToConstructorInjectionRector.php b/packages/Laravel/src/Rector/FuncCall/HelperFunctionToConstructorInjectionRector.php index a7ea324dc22..9ea96125486 100644 --- a/packages/Laravel/src/Rector/FuncCall/HelperFunctionToConstructorInjectionRector.php +++ b/packages/Laravel/src/Rector/FuncCall/HelperFunctionToConstructorInjectionRector.php @@ -223,12 +223,13 @@ PHP */ public function refactor(Node $node): ?Node { - // we can inject only in class context - $classNode = $node->getAttribute(AttributeKey::CLASS_NODE); - if (! $classNode instanceof Class_) { + if ($this->shouldSkipFuncCall($node)) { return null; } + /** @var Class_ $classNode */ + $classNode = $node->getAttribute(AttributeKey::CLASS_NODE); + foreach ($this->functionToService as $function => $service) { if (! $this->isName($node, $function)) { continue; @@ -262,4 +263,25 @@ PHP return null; } + + private function shouldSkipFuncCall(FuncCall $funcCall): bool + { + // we can inject only in class context + $classNode = $funcCall->getAttribute(AttributeKey::CLASS_NODE); + if (! $classNode instanceof Class_) { + return true; + } + + /** @var Node\Stmt\ClassMethod|null $classMethod */ + $classMethod = $funcCall->getAttribute(AttributeKey::METHOD_NODE); + if ($classMethod === null) { + return true; + } + + if ($classMethod->isStatic()) { + return true; + } + + return false; + } } diff --git a/packages/Laravel/tests/Rector/FuncCall/HelperFunctionToConstructorInjectionRector/Fixture/skip_static_method.php.inc b/packages/Laravel/tests/Rector/FuncCall/HelperFunctionToConstructorInjectionRector/Fixture/skip_static_method.php.inc new file mode 100644 index 00000000000..635e638bc05 --- /dev/null +++ b/packages/Laravel/tests/Rector/FuncCall/HelperFunctionToConstructorInjectionRector/Fixture/skip_static_method.php.inc @@ -0,0 +1,11 @@ +