Skip to content

Fix ClassConstFetch use on InvokableCommandInputAttributeRector #778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class NameFromConstant
protected function __invoke(#[\Symfony\Component\Console\Attribute\Argument(name: self::ARGUMENT_NAME, description: 'The name of the person to greet.')]
?string $name, OutputInterface $output): int
{
$name = self::ARGUMENT_NAME;
$name = $name;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mickverm this $name = $name equal is OK, it can be removed via Rector\DeadCode\Rector\Expression\SimplifyMirrorAssignRector with activate deadCode set

https://getrector.com/demo/29ca0dfe-2bf8-4ff9-ac6f-8f1b5e5161b3

$output->writeln("Hello {$name}!");
return Command::SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PhpParser\Node\Stmt\Expression;
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
use Rector\Exception\ShouldNotHappenException;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractRector;
use Rector\Symfony\Enum\CommandMethodName;
use Rector\Symfony\Enum\SymfonyAttribute;
Expand All @@ -40,7 +41,8 @@
public function __construct(
private readonly AttributeFinder $attributeFinder,
private readonly CommandArgumentsAndOptionsResolver $commandArgumentsAndOptionsResolver,
private readonly CommandInvokeParamsFactory $commandInvokeParamsFactory
private readonly CommandInvokeParamsFactory $commandInvokeParamsFactory,
private readonly ValueResolver $valueResolver
) {
}

Expand Down Expand Up @@ -237,7 +239,7 @@

private function replaceInputArgumentOptionFetchWithVariables(ClassMethod $executeClassMethod): void
{
$this->traverseNodesWithCallable($executeClassMethod->stmts, function (Node $node): null|Variable|ClassConstFetch|ConstFetch {

Check failure on line 242 in rules/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector.php

View workflow job for this annotation

GitHub Actions / code_analysis_reusable / PHPStan

Anonymous function never returns PhpParser\Node\Expr\ClassConstFetch so it can be removed from the return type.

Check failure on line 242 in rules/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector.php

View workflow job for this annotation

GitHub Actions / code_analysis_reusable / PHPStan

Anonymous function never returns PhpParser\Node\Expr\ConstFetch so it can be removed from the return type.
if (! $node instanceof MethodCall) {
return null;
}
Expand All @@ -254,7 +256,7 @@
->value;

if ($firstArgValue instanceof ClassConstFetch || $firstArgValue instanceof ConstFetch) {
return $firstArgValue;
return new Variable($this->valueResolver->getValue($firstArgValue));
}

if (! $firstArgValue instanceof String_) {
Expand Down
Loading