Skip to content

Commit fe2a075

Browse files
committed
Revert symfony rules applied to own source
Keep console command metadata in configure() and skip CommandConfigureToAttributeRector, so the set only affects downstream projects.
1 parent 33f6731 commit fe2a075

7 files changed

Lines changed: 33 additions & 12 deletions

File tree

rector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
1010
use Rector\Php84\Rector\Class_\DeprecatedAnnotationToDeprecatedAttributeRector;
1111
use Rector\Symfony\Symfony44\Rector\ClassMethod\ConsoleExecuteReturnIntRector;
12+
use Rector\Symfony\Symfony61\Rector\Class_\CommandConfigureToAttributeRector;
1213

1314
return RectorConfig::configure()
1415
->withPreparedSets(
@@ -45,6 +46,9 @@
4546

4647
// adds (int) cast to methods that already return int, ping-pongs with RecastingRemovalRector
4748
ConsoleExecuteReturnIntRector::class,
49+
50+
// keep console command metadata in configure(), as more readable than a single long attribute
51+
CommandConfigureToAttributeRector::class,
4852
// tests
4953
'*/Fixture*',
5054
'*/Source*',

src/Console/Command/ComposerBasedCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
1414
use Rector\VersionBonding\ValueObject\ComposerBoundRuleConfiguration;
1515
use ReflectionObject;
16-
use Symfony\Component\Console\Attribute\AsCommand;
1716
use Symfony\Component\Console\Command\Command;
1817
use Symfony\Component\Console\Helper\TableCell;
1918
use Symfony\Component\Console\Helper\TableSeparator;
@@ -24,7 +23,6 @@
2423
/**
2524
* @see \Rector\Tests\Console\Command\ComposerBasedCommandTest
2625
*/
27-
#[AsCommand(name: 'composer-based', description: 'Show loaded rules that are triggered by an installed composer package version')]
2826
final class ComposerBasedCommand extends Command
2927
{
3028
/**
@@ -38,6 +36,12 @@ public function __construct(
3836
parent::__construct();
3937
}
4038

39+
protected function configure(): void
40+
{
41+
$this->setName('composer-based');
42+
$this->setDescription('Show loaded rules that are triggered by an installed composer package version');
43+
}
44+
4145
protected function execute(InputInterface $input, OutputInterface $output): int
4246
{
4347
$tableRows = $this->createTableRows();

src/Console/Command/CustomRuleCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010
use Rector\Enum\ClassName;
1111
use Rector\Exception\ShouldNotHappenException;
1212
use Rector\FileSystem\JsonFileSystem;
13-
use Symfony\Component\Console\Attribute\AsCommand;
1413
use Symfony\Component\Console\Command\Command;
1514
use Symfony\Component\Console\Input\InputInterface;
1615
use Symfony\Component\Console\Output\OutputInterface;
1716
use Symfony\Component\Console\Style\SymfonyStyle;
1817
use Symfony\Component\Finder\Finder;
1918
use Symfony\Component\Finder\SplFileInfo;
2019

21-
#[AsCommand(name: 'custom-rule', description: 'Create base of local custom rule with tests')]
2220
final class CustomRuleCommand extends Command
2321
{
2422
public function __construct(
@@ -28,6 +26,12 @@ public function __construct(
2826
parent::__construct();
2927
}
3028

29+
protected function configure(): void
30+
{
31+
$this->setName('custom-rule');
32+
$this->setDescription('Create base of local custom rule with tests');
33+
}
34+
3135
protected function execute(InputInterface $input, OutputInterface $output): int
3236
{
3337
// ask for rule name

src/Console/Command/ListRulesCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010
use Rector\Contract\Rector\RectorInterface;
1111
use Rector\PostRector\Contract\Rector\PostRectorInterface;
1212
use Rector\Skipper\SkipCriteriaResolver\SkippedClassResolver;
13-
use Symfony\Component\Console\Attribute\AsCommand;
1413
use Symfony\Component\Console\Command\Command;
1514
use Symfony\Component\Console\Input\InputInterface;
1615
use Symfony\Component\Console\Input\InputOption;
1716
use Symfony\Component\Console\Output\OutputInterface;
1817
use Symfony\Component\Console\Style\SymfonyStyle;
1918

20-
#[AsCommand(name: 'list-rules', description: 'Show loaded Rectors', aliases: ['show-rules'])]
2119
final class ListRulesCommand extends Command
2220
{
2321
/**
@@ -33,6 +31,11 @@ public function __construct(
3331

3432
protected function configure(): void
3533
{
34+
$this->setName('list-rules');
35+
$this->setDescription('Show loaded Rectors');
36+
37+
$this->setAliases(['show-rules']);
38+
3639
$this->addOption(
3740
Option::OUTPUT_FORMAT,
3841
null,

src/Console/Command/ProcessCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@
2626
use Rector\ValueObject\Configuration\LevelOverflow;
2727
use Rector\ValueObject\ProcessResult;
2828
use Symfony\Component\Console\Application;
29-
use Symfony\Component\Console\Attribute\AsCommand;
3029
use Symfony\Component\Console\Command\Command;
3130
use Symfony\Component\Console\Input\InputInterface;
3231
use Symfony\Component\Console\Output\OutputInterface;
3332
use Symfony\Component\Console\Style\SymfonyStyle;
3433

35-
#[AsCommand(name: 'process', description: 'Upgrades or refactors source code with provided Rector rules', aliases: ['p'])]
3634
final class ProcessCommand extends Command
3735
{
3836
public function __construct(
@@ -55,6 +53,9 @@ public function __construct(
5553

5654
protected function configure(): void
5755
{
56+
$this->setName('process');
57+
$this->setAliases(['p']);
58+
$this->setDescription('Upgrades or refactors source code with provided Rector rules');
5859
$this->setHelp(
5960
<<<'EOF'
6061
The <info>%command.name%</info> command will run Rector main feature:

src/Console/Command/SetupCICommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
use Nette\Utils\FileSystem;
88
use OndraM\CiDetector\CiDetector;
99
use Rector\Git\RepositoryHelper;
10-
use Symfony\Component\Console\Attribute\AsCommand;
1110
use Symfony\Component\Console\Command\Command;
1211
use Symfony\Component\Console\Input\InputInterface;
1312
use Symfony\Component\Console\Output\OutputInterface;
1413
use Symfony\Component\Console\Style\SymfonyStyle;
1514
use function sprintf;
1615

17-
#[AsCommand(name: 'setup-ci', description: 'Add CI workflow to let Rector work for you')]
1816
final class SetupCICommand extends Command
1917
{
2018
public function __construct(
@@ -23,6 +21,12 @@ public function __construct(
2321
parent::__construct();
2422
}
2523

24+
protected function configure(): void
25+
{
26+
$this->setName('setup-ci');
27+
$this->setDescription('Add CI workflow to let Rector work for you');
28+
}
29+
2630
protected function execute(InputInterface $input, OutputInterface $output): int
2731
{
2832
// detect current CI

src/Console/Command/WorkerCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Rector\Util\MemoryLimiter;
2121
use Rector\ValueObject\Configuration;
2222
use Rector\ValueObject\Error\SystemError;
23-
use Symfony\Component\Console\Attribute\AsCommand;
2423
use Symfony\Component\Console\Command\Command;
2524
use Symfony\Component\Console\Input\InputInterface;
2625
use Symfony\Component\Console\Output\OutputInterface;
@@ -37,7 +36,6 @@
3736
* ↓↓↓
3837
* https://github.com/phpstan/phpstan-src/commit/b84acd2e3eadf66189a64fdbc6dd18ff76323f67#diff-7f625777f1ce5384046df08abffd6c911cfbb1cfc8fcb2bdeaf78f337689e3e2
3938
*/
40-
#[AsCommand(name: 'worker', description: '[INTERNAL] Support for parallel process')]
4139
final class WorkerCommand extends Command
4240
{
4341
private const string RESULT = 'result';
@@ -55,6 +53,9 @@ public function __construct(
5553

5654
protected function configure(): void
5755
{
56+
$this->setName('worker');
57+
$this->setDescription('[INTERNAL] Support for parallel process');
58+
5859
ProcessConfigureDecorator::decorate($this);
5960

6061
parent::configure();

0 commit comments

Comments
 (0)