diff --git a/rules-tests/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector/Fixture/skip_first_class_callable.php.inc b/rules-tests/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector/Fixture/skip_first_class_callable.php.inc new file mode 100644 index 000000000..1690b1b1e --- /dev/null +++ b/rules-tests/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector/Fixture/skip_first_class_callable.php.inc @@ -0,0 +1,20 @@ +services(); + + $services->defaults()->autowire(); + + $services->set('named-class', AnotherClassWithoutConstructor::class) + ->arg('$passedAsDependency', service(...)); +}; + +?> \ No newline at end of file diff --git a/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php b/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php index 2c44e4cb8..298a7a92d 100644 --- a/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php +++ b/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php @@ -129,6 +129,10 @@ public function refactor(Node $node): ?Node return null; } + if ($node->isFirstClassCallable()) { + return null; + } + $argName = $node->getArgs()[0] ->value; $serviceArgExpr = $node->getArgs()[1] @@ -186,6 +190,10 @@ private function matchSetServicesClass(MethodCall $methodCall): ?string return null; } + if ($methodCall->isFirstClassCallable()) { + return null; + } + foreach ($methodCall->getArgs() as $arg) { if (! $arg->value instanceof ClassConstFetch) { continue; @@ -209,6 +217,10 @@ private function isParameterTypeMatchingPassedArgExprClass( return false; } + if ($serviceArgExpr->isFirstClassCallable()) { + return false; + } + $dependencyServiceExpr = $serviceArgExpr->getArgs()[0] ->value; $dependencyService = $this->valueResolver->getValue($dependencyServiceExpr);