From ed0e68f2ffc359f0601e12011e8fb6c41bb5de58 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 27 Oct 2025 09:00:30 +0700 Subject: [PATCH 1/3] [Configs] Skip first class callable on RemoveConstructorAutowireServiceRector --- .../Fixture/skip_first_class_callable.php.inc | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 rules-tests/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector/Fixture/skip_first_class_callable.php.inc 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 From 7098da8323dfef0239c8b8eaaf61886b68319e10 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 27 Oct 2025 09:01:34 +0700 Subject: [PATCH 2/3] [Configs] Skip first class callable on RemoveConstructorAutowireServiceRector --- .../Closure/RemoveConstructorAutowireServiceRector.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php b/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php index 2c44e4cb8..4926c9e1b 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; From efa5544160fb9dcad469b837da5424e5f9f81c20 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 27 Oct 2025 09:01:54 +0700 Subject: [PATCH 3/3] [Configs] Skip first class callable on RemoveConstructorAutowireServiceRector --- .../Rector/Closure/RemoveConstructorAutowireServiceRector.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php b/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php index 4926c9e1b..298a7a92d 100644 --- a/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php +++ b/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php @@ -217,6 +217,10 @@ private function isParameterTypeMatchingPassedArgExprClass( return false; } + if ($serviceArgExpr->isFirstClassCallable()) { + return false; + } + $dependencyServiceExpr = $serviceArgExpr->getArgs()[0] ->value; $dependencyService = $this->valueResolver->getValue($dependencyServiceExpr);