rector icon indicating copy to clipboard operation
rector copied to clipboard

Error: Could not process Command with options

Open knallcharge opened this issue 10 months ago • 6 comments

I'm using Rector 2.0.17, PHP 8.4.7, Symfony 7.3.0 and starting with the last version of rector I'm receiving an error that two Command-classes cannot be processed. I have a couple of other Commands which don't throw the error and found that the two have an option (arguments work fine) which seems to cause the problem.

These are the included files/rules:

[info] Sets loaded based on installed packages:
 * (...)\vendor\rector\rector\vendor\rector\rector-doctrine\config\sets\doctrine-bundle-23.php
 * (...)\vendor\rector\rector\vendor\rector\rector-doctrine\config\sets\doctrine-bundle-28.php
 * (...)\vendor\rector\rector\vendor\rector\rector-doctrine\config\sets\doctrine-dbal-40.php
 * (...)\vendor\rector\rector\vendor\rector\rector-doctrine\config\sets\doctrine-orm-300.php
 * (...)\vendor\rector\rector\vendor\rector\rector-symfony\config\sets\symfony\symfony7\symfony70\symfony70-dependency-injection.php
 * (...)\vendor\rector\rector\vendor\rector\rector-symfony\config\sets\symfony\symfony7\symfony70\symfony70-serializer.php
 * (...)\vendor\rector\rector\vendor\rector\rector-symfony\config\sets\symfony\symfony7\symfony70\symfony70-http-foundation.php
 * (...)\vendor\rector\rector\vendor\rector\rector-symfony\config\sets\symfony\symfony7\symfony71\symfony71-dependency-injection.php
 * (...)\vendor\rector\rector\vendor\rector\rector-symfony\config\sets\symfony\symfony7\symfony71\symfony71-serializer.php
 * (...)\vendor\rector\rector\vendor\rector\rector-symfony\config\sets\symfony\symfony7\symfony72\symfony72-serializer.php
 * (...)\vendor\rector\rector\vendor\rector\rector-symfony\config\sets\symfony\symfony7\symfony73\symfony73-console.php
 * (...)\vendor\rector\rector\vendor\rector\rector-symfony\config\sets\symfony\symfony7\symfony73\symfony73-twig-bundle.php

My settings:

->withAttributesSets()
->withComposerBased(twig: true, doctrine: true, phpunit: true, symfony: true)

And this is one of the stack traces that rectors prints out when using --debug:

#0 (...)\vendor\rector\rector\vendor\rector\rector-symfony\rules\Symfony73\Rector\Class_\InvokableCommandInputAttributeRector.php(160):
Rector\Symfony\Symfony73\NodeAnalyzer\CommandArgumentsAndOptionsResolver->collectCommandOptions(Object(PhpParser\Node\Stmt\ClassMethod))
#1 (...)\vendor\rector\rector\src\Rector\AbstractRector.php(112):
Rector\Symfony\Symfony73\Rector\Class_\InvokableCommandInputAttributeRector->refactor(Object(PhpParser\Node\Stmt\Class_))
#2 (...)\vendor\rector\rector\vendor\nikic\php-parser\lib\PhpParser\NodeTraverser.php(173):
Rector\Rector\AbstractRector->enterNode(Object(PhpParser\Node\Stmt\Class_))
#3 (...)\vendor\rector\rector\vendor\nikic\php-parser\lib\PhpParser\NodeTraverser.php(90):
PhpParser\NodeTraverser->traverseArray(Array)
#4 (...)\vendor\rector\rector\vendor\nikic\php-parser\lib\PhpParser\NodeTraverser.php(200):
PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Namespace_))
#5 (...)\vendor\rector\rector\vendor\nikic\php-parser\lib\PhpParser\NodeTraverser.php(71):
PhpParser\NodeTraverser->traverseArray(Array)
#6 (...)\vendor\rector\rector\src\PhpParser\NodeTraverser\RectorNodeTraverser.php(49):
PhpParser\NodeTraverser->traverse(Array)
#7 (...)\vendor\rector\rector\src\Application\FileProcessor.php(95):
Rector\PhpParser\NodeTraverser\RectorNodeTraverser->traverse(Array)
#8 (...)\vendor\rector\rector\src\Application\ApplicationFileProcessor.php(174):
Rector\Application\FileProcessor->processFile(Object(Rector\ValueObject\Application\File), Object(Rector\ValueObject\Configuration))
#9 (...)\vendor\rector\rector\src\Application\ApplicationFileProcessor.php(151):
Rector\Application\ApplicationFileProcessor->processFile(Object(Rector\ValueObject\Application\File), Object(Rector\ValueObject\Configuration))
#10 (...)\vendor\rector\rector\src\Application\ApplicationFileProcessor.php(128):
Rector\Application\ApplicationFileProcessor->processFiles(Array, Object(Rector\ValueObject\Configuration), Object(Closure), Object(Closure))
#11 (...)\vendor\rector\rector\src\Console\Command\ProcessCommand.php(172):
Rector\Application\ApplicationFileProcessor->run(Object(Rector\ValueObject\Configuration), Object(RectorPrefix202505\Symfony\Component\Console\Input\ArgvInput))
#12 (...)\vendor\rector\rector\vendor\symfony\console\Command\Command.php(285):
Rector\Console\Command\ProcessCommand->execute(Object(RectorPrefix202505\Symfony\Component\Console\Input\ArgvInput), Object(RectorPrefix202505\Symfony\Component\Console\Output\ConsoleOutput))
#13 (...)\vendor\rector\rector\vendor\symfony\console\Application.php(900):
RectorPrefix202505\Symfony\Component\Console\Command\Command->run(Object(RectorPrefix202505\Symfony\Component\Console\Input\ArgvInput), Object(RectorPrefix202505\Symfony\Component\Console\Output\ConsoleOutput))
#14 (...)\vendor\rector\rector\vendor\symfony\console\Application.php(279):
RectorPrefix202505\Symfony\Component\Console\Application->doRunCommand(Object(Rector\Console\Command\ProcessCommand), Object(RectorPrefix202505\Symfony\Component\Console\Input\ArgvInput), Object(RectorPrefix202505\Symfony\Component\Console\Output\ConsoleOutput))
#15 (...)\vendor\rector\rector\src\Console\ConsoleApplication.php(63):
RectorPrefix202505\Symfony\Component\Console\Application->doRun(Object(RectorPrefix202505\Symfony\Component\Console\Input\ArgvInput), Object(RectorPrefix202505\Symfony\Component\Console\Output\ConsoleOutput))
#16 (...)\vendor\rector\rector\vendor\symfony\console\Application.php(162):
Rector\Console\ConsoleApplication->doRun(Object(RectorPrefix202505\Symfony\Component\Console\Input\ArgvInput), Object(RectorPrefix202505\Symfony\Component\Console\Output\ConsoleOutput))
#17 (...)\vendor\rector\rector\bin\rector.php(130):
RectorPrefix202505\Symfony\Component\Console\Application->run()
#18 (...)\vendor\rector\rector\bin\rector(5):
require_once('C:\\xampp\\htdocs...')
#19 (...)\vendor\bin\rector(119): include('C:\\xampp\\htdocs...')
#20 {main}". On line: 68

The problem is gone when I:

  • skip \Rector\Symfony\Symfony73\Rector\Class_\InvokableCommandInputAttributeRector::class in my rector.php OR
  • remove ->addOption from my code and switch to an argument (which is not really an option, pun intended :))

knallcharge avatar Jun 06 '25 06:06 knallcharge

Could you create expected fixture PR test on https://github.com/rectorphp/rector-symfony/tree/main/rules-tests/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector/Fixture (better with add patch as well)? Thank you.

samsonasik avatar Jun 06 '25 06:06 samsonasik

Sorry, I don't know what that means.

knallcharge avatar Jun 06 '25 06:06 knallcharge

we need expected output for given input, before vs after on the fixture file test separated by ----- , see example https://github.com/rectorphp/rector-symfony/blob/main/rules-tests/Symfony73/Rector/Class_/InvokableCommandInputAttributeRector/Fixture/some_command.php.inc

samsonasik avatar Jun 06 '25 06:06 samsonasik

I don't know anything about the rector internals at all, I'll have to see if I find some time on the weekend to understand the requirements.

knallcharge avatar Jun 06 '25 07:06 knallcharge

The code before ----- is represent input content, and after it represent expected output, when we have it, we can see what, why, and possible fix

samsonasik avatar Jun 06 '25 07:06 samsonasik

Ok, than I'll have to find out what the expected output is, first :)

knallcharge avatar Jun 06 '25 08:06 knallcharge

I am going to close this, feel free to create failing fixture PR when you have a chance so it can be properly fixed, thank you.

samsonasik avatar Jun 27 '25 10:06 samsonasik

This issue has been automatically locked because it has been closed for 150 days. Please open a new issue if you have a similar problem.

github-actions[bot] avatar Nov 28 '25 03:11 github-actions[bot]