diff --git a/rules-tests/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector/Fixture/name_from_constant.php.inc b/rules-tests/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector/Fixture/name_from_constant.php.inc new file mode 100644 index 00000000..f5a8234b --- /dev/null +++ b/rules-tests/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector/Fixture/name_from_constant.php.inc @@ -0,0 +1,64 @@ +addArgument(self::ARGUMENT_NAME, InputArgument::OPTIONAL, 'The name of the person to greet.'); + } + + #[\Override] + protected function execute(InputInterface $input, OutputInterface $output): int + { + $name = $input->getArgument(self::ARGUMENT_NAME); + $output->writeln("Hello {$name}!"); + + return Command::SUCCESS; + } +} + +?> +----- +writeln("Hello {$name}!"); + return Command::SUCCESS; + } +} + +?> \ No newline at end of file diff --git a/rules/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector.php b/rules/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector.php index 21286b50..b2315588 100644 --- a/rules/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector.php +++ b/rules/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector.php @@ -6,6 +6,8 @@ use PhpParser\Node; use PhpParser\Node\Attribute; +use PhpParser\Node\Expr\ClassConstFetch; +use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; @@ -235,7 +237,7 @@ private function removeConfigureClassMethod(Class_ $class): void private function replaceInputArgumentOptionFetchWithVariables(ClassMethod $executeClassMethod): void { - $this->traverseNodesWithCallable($executeClassMethod->stmts, function (Node $node): ?Variable { + $this->traverseNodesWithCallable($executeClassMethod->stmts, function (Node $node): null|Variable|ClassConstFetch|ConstFetch { if (! $node instanceof MethodCall) { return null; } @@ -251,6 +253,10 @@ private function replaceInputArgumentOptionFetchWithVariables(ClassMethod $execu $firstArgValue = $node->getArgs()[0] ->value; + if ($firstArgValue instanceof ClassConstFetch || $firstArgValue instanceof ConstFetch) { + return $firstArgValue; + } + if (! $firstArgValue instanceof String_) { // unable to resolve argument/option name throw new ShouldNotHappenException();