From 5fbf1a1c6b7148b69d6e05db79a28b7524bbf627 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 26 Oct 2025 15:11:36 +0100 Subject: [PATCH] add fixture --- .../Fixture/named_class.php.inc | 42 +++++++++++++++++++ ...RemoveConstructorAutowireServiceRector.php | 14 +++++-- 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 rules-tests/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector/Fixture/named_class.php.inc diff --git a/rules-tests/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector/Fixture/named_class.php.inc b/rules-tests/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector/Fixture/named_class.php.inc new file mode 100644 index 000000000..ac0977c7d --- /dev/null +++ b/rules-tests/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector/Fixture/named_class.php.inc @@ -0,0 +1,42 @@ +services(); + + $services->defaults()->autowire(); + + $services->set('named-class', AnotherClassWithoutConstructor::class) + ->arg('$passedAsDependency', service(PassedAsDependency::class)); +}; + +?> +----- +services(); + + $services->defaults()->autowire(); + + $services->set('named-class', AnotherClassWithoutConstructor::class); +}; + +?> diff --git a/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php b/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php index 7f8372a7d..2c44e4cb8 100644 --- a/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php +++ b/rules/Configs/Rector/Closure/RemoveConstructorAutowireServiceRector.php @@ -182,13 +182,19 @@ private function matchSetServicesClass(MethodCall $methodCall): ?string $methodCall = $methodCall->var; } - /** @var MethodCall $methodCall */ - $firstArg = $methodCall->getArgs()[0]; - if (! $firstArg->value instanceof ClassConstFetch) { + if (! $methodCall instanceof MethodCall) { return null; } - return $this->valueResolver->getValue($firstArg->value); + foreach ($methodCall->getArgs() as $arg) { + if (! $arg->value instanceof ClassConstFetch) { + continue; + } + + return $this->valueResolver->getValue($arg->value); + } + + return null; } private function isParameterTypeMatchingPassedArgExprClass(