Skip to content

Commit 4eca735

Browse files
authored
[Console] Deprecate list-rules command (#8396)
1 parent 64d5c95 commit 4eca735

1 file changed

Lines changed: 5 additions & 84 deletions

File tree

‎src/Console/Command/ListRulesCommand.php‎

Lines changed: 5 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,112 +4,33 @@
44

55
namespace Rector\Console\Command;
66

7-
use Nette\Utils\Json;
8-
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
9-
use Rector\Configuration\Option;
10-
use Rector\Contract\Rector\RectorInterface;
11-
use Rector\PostRector\Contract\Rector\PostRectorInterface;
12-
use Rector\Skipper\SkipCriteriaResolver\SkippedClassResolver;
137
use Symfony\Component\Console\Command\Command;
148
use Symfony\Component\Console\Input\InputInterface;
15-
use Symfony\Component\Console\Input\InputOption;
169
use Symfony\Component\Console\Output\OutputInterface;
1710
use Symfony\Component\Console\Style\SymfonyStyle;
1811

1912
final class ListRulesCommand extends Command
2013
{
21-
/**
22-
* @param RectorInterface[] $rectors
23-
*/
2414
public function __construct(
25-
private readonly SymfonyStyle $symfonyStyle,
26-
private readonly SkippedClassResolver $skippedClassResolver,
27-
private readonly array $rectors
15+
private readonly SymfonyStyle $symfonyStyle
2816
) {
2917
parent::__construct();
3018
}
3119

3220
protected function configure(): void
3321
{
3422
$this->setName('list-rules');
35-
$this->setDescription('Show loaded Rectors');
23+
$this->setDescription('[DEPRECATED] Show loaded Rectors');
3624

3725
$this->setAliases(['show-rules']);
38-
39-
$this->addOption(
40-
Option::OUTPUT_FORMAT,
41-
null,
42-
InputOption::VALUE_REQUIRED,
43-
'Select output format',
44-
ConsoleOutputFormatter::NAME
45-
);
46-
47-
$this->addOption(Option::ONLY, null, InputOption::VALUE_REQUIRED, 'Fully qualified rule class name');
4826
}
4927

5028
protected function execute(InputInterface $input, OutputInterface $output): int
5129
{
52-
$rectorClasses = $this->resolveRectorClasses();
53-
54-
$skippedClasses = $this->getSkippedRectorClasses();
55-
56-
$outputFormat = $input->getOption(Option::OUTPUT_FORMAT);
57-
if ($outputFormat === 'json') {
58-
$data = [
59-
'rectors' => $rectorClasses,
60-
'skipped-rectors' => $skippedClasses,
61-
];
62-
63-
echo Json::encode($data, pretty: true) . PHP_EOL;
64-
return Command::SUCCESS;
65-
}
66-
67-
$this->symfonyStyle->title('Loaded Rector rules');
68-
$this->symfonyStyle->listing($rectorClasses);
69-
70-
if ($skippedClasses !== []) {
71-
$this->symfonyStyle->title('Skipped Rector rules');
72-
$this->symfonyStyle->listing($skippedClasses);
73-
}
74-
75-
$this->symfonyStyle->newLine();
76-
$this->symfonyStyle->note(sprintf('Loaded %d rules', count($rectorClasses)));
77-
78-
return Command::SUCCESS;
79-
}
80-
81-
/**
82-
* @return array<class-string<RectorInterface>>
83-
*/
84-
private function resolveRectorClasses(): array
85-
{
86-
$customRectors = array_filter(
87-
$this->rectors,
88-
static fn (RectorInterface $rector): bool => ! $rector instanceof PostRectorInterface
30+
$this->symfonyStyle->error(
31+
'The "list-rules" command is deprecated and no longer provided. Run Rector with the set or rules you desire instead.'
8932
);
9033

91-
$rectorClasses = array_map(static fn (RectorInterface $rector): string => $rector::class, $customRectors);
92-
sort($rectorClasses);
93-
94-
return array_unique($rectorClasses);
95-
}
96-
97-
/**
98-
* @return array<class-string>
99-
*/
100-
private function getSkippedRectorClasses(): array
101-
{
102-
$skippedRectorClasses = [];
103-
104-
foreach ($this->skippedClassResolver->resolve() as $rectorClass => $fileList) {
105-
// ignore specific skips
106-
if ($fileList !== null) {
107-
continue;
108-
}
109-
110-
$skippedRectorClasses[] = $rectorClass;
111-
}
112-
113-
return $skippedRectorClasses;
34+
return Command::FAILURE;
11435
}
11536
}

0 commit comments

Comments
 (0)