From b564a365402c7a3c93bcae4c764fd67e039d3919 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 23 Oct 2026 10:25:49 +0200 Subject: [PATCH] [Console] Add #[AsCommand] attribute to console commands --- src/Console/Command/ComposerBasedCommand.php | 3 ++- src/Console/Command/CustomRuleCommand.php | 3 ++- src/Console/Command/ListRulesCommand.php | 3 ++- src/Console/Command/ProcessCommand.php | 3 ++- src/Console/Command/SetupCICommand.php | 3 ++- src/Console/Command/ValidateConfigCommand.php | 3 ++- src/Console/Command/WorkerCommand.php | 3 ++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Console/Command/ComposerBasedCommand.php b/src/Console/Command/ComposerBasedCommand.php index 60be06c7729..c96d429d6df 100644 --- a/src/Console/Command/ComposerBasedCommand.php +++ b/src/Console/Command/ComposerBasedCommand.php @@ -13,6 +13,7 @@ use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface; use Rector\VersionBonding\ValueObject\ComposerBoundRuleConfiguration; use ReflectionObject; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\TableCell; use Symfony\Component\Console\Helper\TableSeparator; @@ -23,6 +24,7 @@ /** * @see \Rector\Tests\Console\Command\ComposerBasedCommandTest */ +#[AsCommand(name: 'composer-based')] final class ComposerBasedCommand extends Command { /** @@ -38,7 +40,6 @@ public function __construct( protected function configure(): void { - $this->setName('composer-based'); $this->setDescription('Show loaded rules that are triggered by an installed composer package version'); } diff --git a/src/Console/Command/CustomRuleCommand.php b/src/Console/Command/CustomRuleCommand.php index af97edcce63..96abc5735ad 100644 --- a/src/Console/Command/CustomRuleCommand.php +++ b/src/Console/Command/CustomRuleCommand.php @@ -4,11 +4,13 @@ namespace Rector\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +#[AsCommand(name: 'custom-rule')] final class CustomRuleCommand extends Command { public function __construct( @@ -19,7 +21,6 @@ public function __construct( protected function configure(): void { - $this->setName('custom-rule'); $this->setDescription('[DEPRECATED] Create base of local custom rule with tests'); } diff --git a/src/Console/Command/ListRulesCommand.php b/src/Console/Command/ListRulesCommand.php index 182660b20ca..c0342610904 100644 --- a/src/Console/Command/ListRulesCommand.php +++ b/src/Console/Command/ListRulesCommand.php @@ -11,12 +11,14 @@ use Rector\Contract\Rector\RectorInterface; use Rector\PostRector\Contract\Rector\PostRectorInterface; use Rector\Skipper\Skipper\Skipper; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +#[AsCommand(name: 'list-rules')] final class ListRulesCommand extends Command { /** @@ -33,7 +35,6 @@ public function __construct( protected function configure(): void { - $this->setName('list-rules'); $this->setDescription('Show loaded Rectors'); $this->setAliases(['show-rules']); diff --git a/src/Console/Command/ProcessCommand.php b/src/Console/Command/ProcessCommand.php index c8202761d3a..f8a43152725 100644 --- a/src/Console/Command/ProcessCommand.php +++ b/src/Console/Command/ProcessCommand.php @@ -25,11 +25,13 @@ use Rector\ValueObject\Configuration\LevelOverflow; use Rector\ValueObject\ProcessResult; use Symfony\Component\Console\Application; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +#[AsCommand(name: 'process')] final class ProcessCommand extends Command { public function __construct( @@ -52,7 +54,6 @@ public function __construct( protected function configure(): void { - $this->setName('process'); $this->setAliases(['p']); $this->setDescription('Upgrades or refactors source code with provided Rector rules'); $this->setHelp( diff --git a/src/Console/Command/SetupCICommand.php b/src/Console/Command/SetupCICommand.php index 38d5bc85db5..41cdb371367 100644 --- a/src/Console/Command/SetupCICommand.php +++ b/src/Console/Command/SetupCICommand.php @@ -4,11 +4,13 @@ namespace Rector\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +#[AsCommand(name: 'setup-ci')] final class SetupCICommand extends Command { public function __construct( @@ -19,7 +21,6 @@ public function __construct( protected function configure(): void { - $this->setName('setup-ci'); $this->setDescription('[DEPRECATED] Add CI workflow to let Rector work for you'); } diff --git a/src/Console/Command/ValidateConfigCommand.php b/src/Console/Command/ValidateConfigCommand.php index 064cdab6ed2..1831995ac4a 100644 --- a/src/Console/Command/ValidateConfigCommand.php +++ b/src/Console/Command/ValidateConfigCommand.php @@ -13,6 +13,7 @@ use Rector\Reporting\MissConfigurationReporter; use Rector\Skipper\Skipper\Skipper; use Rector\ValueObject\Configuration; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -22,6 +23,7 @@ /** * @see \Rector\Tests\Console\Command\ValidateConfigCommandTest */ +#[AsCommand(name: 'validate-config')] final class ValidateConfigCommand extends Command { public function __construct( @@ -35,7 +37,6 @@ public function __construct( protected function configure(): void { - $this->setName('validate-config'); $this->setDescription('Report config hygiene issues without processing any files'); $this->addOption( Option::OUTPUT_FORMAT, diff --git a/src/Console/Command/WorkerCommand.php b/src/Console/Command/WorkerCommand.php index 8b7d4c1061c..0a0acf39e2a 100644 --- a/src/Console/Command/WorkerCommand.php +++ b/src/Console/Command/WorkerCommand.php @@ -24,6 +24,7 @@ use Rector\Util\MemoryLimiter; use Rector\ValueObject\Configuration; use Rector\ValueObject\Error\SystemError; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -37,6 +38,7 @@ * ↓↓↓ * https://github.com/phpstan/phpstan-src/commit/b84acd2e3eadf66189a64fdbc6dd18ff76323f67#diff-7f625777f1ce5384046df08abffd6c911cfbb1cfc8fcb2bdeaf78f337689e3e2 */ +#[AsCommand(name: 'worker')] final class WorkerCommand extends Command { private const string RESULT = 'result'; @@ -54,7 +56,6 @@ public function __construct( protected function configure(): void { - $this->setName('worker'); $this->setDescription('[INTERNAL] Support for parallel process'); ProcessConfigureDecorator::decorate($this);