Skip to content

Commit 1547cf1

Browse files
committed
Updated Rector to commit 27c5f897750ebb175a96e894d13041c31a2c054d
rectorphp/rector-src@27c5f89 [Console] Allow --only to run several rules at once (#8451)
1 parent c7eef3b commit 1547cf1

8 files changed

Lines changed: 42 additions & 29 deletions

File tree

src/Application/ApplicationFileProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function __construct(SymfonyStyle $symfonyStyle, FilesFinder $filesFinder
9999
public function run(Configuration $configuration, InputInterface $input): ProcessResult
100100
{
101101
// scope the cache to this run's --only / --only-suffix selection before any cache read/write
102-
$this->changedFilesDetector->setActiveScope($configuration->getOnlyRule(), $configuration->getOnlySuffix(), $configuration->getFilters());
102+
$this->changedFilesDetector->setActiveScope($configuration->getOnlyRules(), $configuration->getOnlySuffix(), $configuration->getFilters());
103103
$filePaths = $this->filesFinder->findFilesInPaths($configuration->getPaths(), $configuration);
104104
// no files found
105105
if ($filePaths === []) {
@@ -150,7 +150,7 @@ public function run(Configuration $configuration, InputInterface $input): Proces
150150
public function processFiles(array $filePaths, Configuration $configuration, ?callable $preFileCallback = null, ?callable $postFileCallback = null): ProcessResult
151151
{
152152
// also set here: parallel workers reach processFiles() via WorkerCommand, bypassing run()
153-
$this->changedFilesDetector->setActiveScope($configuration->getOnlyRule(), $configuration->getOnlySuffix(), $configuration->getFilters());
153+
$this->changedFilesDetector->setActiveScope($configuration->getOnlyRules(), $configuration->getOnlySuffix(), $configuration->getFilters());
154154
/** @var SystemError[] $systemErrors */
155155
$systemErrors = [];
156156
/** @var FileDiff[] $fileDiffs */

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '0ee1347fda56433334b34f2298c14ae493cee30a';
22+
public const PACKAGE_VERSION = '27c5f897750ebb175a96e894d13041c31a2c054d';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2026-09-03 23:51:46';
27+
public const RELEASE_DATE = '2026-09-04 00:56:54';
2828
/**
2929
* @var int
3030
*/

src/Caching/Detector/ChangedFilesDetector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ public function __construct(FileHashComputer $fileHashComputer, Cache $cache, Fi
4040
$this->fileHasher = $fileHasher;
4141
}
4242
/**
43+
* @param string[] $onlyRules
4344
* @param string[] $filters
4445
*/
45-
public function setActiveScope(?string $onlyRule, ?string $onlySuffix, array $filters = []): void
46+
public function setActiveScope(array $onlyRules, ?string $onlySuffix, array $filters = []): void
4647
{
4748
// each selection gets its own cache key, so --only and full runs coexist without clearing or poisoning
48-
$this->scopeSuffix = $onlyRule === null && $onlySuffix === null && $filters === [] ? '' : '|only:' . ($onlyRule ?? '') . '|suffix:' . ($onlySuffix ?? '') . '|filter:' . implode(',', $filters);
49+
$this->scopeSuffix = $onlyRules === [] && $onlySuffix === null && $filters === [] ? '' : '|only:' . implode(',', $onlyRules) . '|suffix:' . ($onlySuffix ?? '') . '|filter:' . implode(',', $filters);
4950
}
5051
public function cacheFile(string $filePath): void
5152
{

src/Configuration/ConfigurationFactory.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ public function createFromInput(InputInterface $input): Configuration
5555
$paths = $this->resolvePaths($input);
5656
$fileExtensions = SimpleParameterProvider::provideArrayParameter(\Rector\Configuration\Option::FILE_EXTENSIONS);
5757
// filter rule and path
58-
$onlyRule = $input->getOption(\Rector\Configuration\Option::ONLY);
59-
if ($onlyRule !== null) {
60-
$onlyRule = $this->onlyRuleResolver->resolve($onlyRule);
61-
}
58+
/** @var string[] $onlyRuleInputs */
59+
$onlyRuleInputs = (array) $input->getOption(\Rector\Configuration\Option::ONLY);
60+
$onlyRules = array_map(\Closure::fromCallable([$this->onlyRuleResolver, 'resolve']), $onlyRuleInputs);
6261
$onlySuffix = $input->getOption(\Rector\Configuration\Option::ONLY_SUFFIX);
6362
if ($onlySuffix !== null) {
6463
$this->symfonyStyle->warning('The "--only-suffix" option is deprecated and will be removed. Use "--filter" instead, e.g. --filter="*Controller.php"');
@@ -67,7 +66,7 @@ public function createFromInput(InputInterface $input): Configuration
6766
$filters = $rawFilter !== null ? $this->filePathFilter->parsePatterns((string) $rawFilter) : [];
6867
// "--only"/"--only-suffix"/"--filter" narrow the run, so skips outside the scope look falsely unused;
6968
// mark the run as narrowed to disable unused skip reporting and avoid false positives
70-
if ($onlyRule !== null || $onlySuffix !== null || $filters !== []) {
69+
if ($onlyRules !== [] || $onlySuffix !== null || $filters !== []) {
7170
SimpleParameterProvider::setParameter(\Rector\Configuration\Option::IS_RUN_NARROWED, \true);
7271
}
7372
$isParallel = SimpleParameterProvider::provideBoolParameter(\Rector\Configuration\Option::PARALLEL);
@@ -97,7 +96,7 @@ public function createFromInput(InputInterface $input): Configuration
9796
if ($isPhpOnly) {
9897
SimpleParameterProvider::setParameter(\Rector\Configuration\Option::IS_RUN_NARROWED, \true);
9998
}
100-
return new Configuration($isDryRun, $showProgressBar, $shouldClearCache, $outputFormat, $fileExtensions, $paths, $showDiffs, $parallelPort, $parallelIdentifier, $isParallel, $memoryLimit, $isDebug, $isReportingWithRealPath, $onlyRule, $onlySuffix, $levelOverflows, $showRulesSummary, $isComposerBased, $isPhpOnly, $filters, $maxChanges);
99+
return new Configuration($isDryRun, $showProgressBar, $shouldClearCache, $outputFormat, $fileExtensions, $paths, $showDiffs, $parallelPort, $parallelIdentifier, $isParallel, $memoryLimit, $isDebug, $isReportingWithRealPath, $onlyRules, $onlySuffix, $levelOverflows, $showRulesSummary, $isComposerBased, $isPhpOnly, $filters, $maxChanges);
101100
}
102101
private function resolveMaxChanges(InputInterface $input): ?int
103102
{

src/Configuration/ConfigurationRuleFilter.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public function filter(array $rectors): array
3333
if (!$this->configuration instanceof Configuration) {
3434
return $rectors;
3535
}
36-
$onlyRule = $this->configuration->getOnlyRule();
37-
if ($onlyRule !== null) {
38-
return $this->filterOnlyRule($rectors, $onlyRule);
36+
$onlyRules = $this->configuration->getOnlyRules();
37+
if ($onlyRules !== []) {
38+
return $this->filterOnlyRules($rectors, $onlyRules);
3939
}
4040
if ($this->configuration->isComposerBased()) {
4141
return $this->filterComposerBased($rectors);
@@ -47,14 +47,18 @@ public function filter(array $rectors): array
4747
}
4848
/**
4949
* @param list<RectorInterface> $rectors
50+
* @param string[] $onlyRules
5051
* @return list<RectorInterface>
5152
*/
52-
public function filterOnlyRule(array $rectors, string $onlyRule): array
53+
public function filterOnlyRules(array $rectors, array $onlyRules): array
5354
{
5455
$activeRectors = [];
5556
foreach ($rectors as $rector) {
56-
if ($rector instanceof $onlyRule) {
57-
$activeRectors[] = $rector;
57+
foreach ($onlyRules as $onlyRule) {
58+
if ($rector instanceof $onlyRule) {
59+
$activeRectors[] = $rector;
60+
break;
61+
}
5862
}
5963
}
6064
return $activeRectors;

src/Console/ProcessConfigureDecorator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function decorate(Command $command): void
1919
$command->addOption(Option::NO_DIFFS, null, InputOption::VALUE_NONE, 'Hide diffs of changed files. Useful e.g. for nicer CI output.');
2020
$command->addOption(Option::OUTPUT_FORMAT, null, InputOption::VALUE_REQUIRED, 'Select output format', ConsoleOutputFormatter::NAME);
2121
// filter by rule and path
22-
$command->addOption(Option::ONLY, null, InputOption::VALUE_REQUIRED, 'Fully qualified rule class name');
22+
$command->addOption(Option::ONLY, null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Fully qualified rule class name; repeat to run several rules, e.g. --only=A --only=B');
2323
$command->addOption(Option::COMPOSER_BASED, null, InputOption::VALUE_NONE, 'Run only rules bound to an installed composer package version');
2424
$command->addOption(Option::PHP, null, InputOption::VALUE_NONE, 'Run only PHP rules, e.g. rules bound to a minimal PHP version');
2525
$command->addOption(Option::ONLY_SUFFIX, null, InputOption::VALUE_REQUIRED, 'Deprecated, use "--filter" instead. Filter only files with specific suffix in name, e.g. "Controller"');

src/Parallel/Command/WorkerCommandLineFactory.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ public function create(string $mainScript, string $mainCommandClass, string $wor
109109
if ((bool) $input->getOption(Option::COMPOSER_BASED)) {
110110
$workerCommandArray[] = self::OPTION_DASHES . Option::COMPOSER_BASED;
111111
}
112-
if ($input->getOption(Option::ONLY) !== null) {
113-
$workerCommandArray[] = self::OPTION_DASHES . Option::ONLY;
114-
$workerCommandArray[] = escapeshellarg((string) $input->getOption(Option::ONLY));
115-
}
116112
return implode(' ', $workerCommandArray);
117113
}
118114
private function shouldSkipOption(InputInterface $input, string $optionName): bool
@@ -148,7 +144,7 @@ private function mirrorCommandOptions(InputInterface $input, array $mainCommandO
148144
if ($this->shouldSkipOption($input, $mainCommandOptionName)) {
149145
continue;
150146
}
151-
/** @var bool|string|null $optionValue */
147+
/** @var bool|string|string[]|null $optionValue */
152148
$optionValue = $input->getOption($mainCommandOptionName);
153149
// skip clutter
154150
if ($optionValue === null) {
@@ -160,6 +156,14 @@ private function mirrorCommandOptions(InputInterface $input, array $mainCommandO
160156
}
161157
continue;
162158
}
159+
// array options (e.g. repeated --only) are mirrored one flag per value
160+
if (is_array($optionValue)) {
161+
foreach ($optionValue as $singleOptionValue) {
162+
$workerCommandOptions[] = self::OPTION_DASHES . $mainCommandOptionName;
163+
$workerCommandOptions[] = \escapeshellarg($singleOptionValue);
164+
}
165+
continue;
166+
}
163167
if ($mainCommandOptionName === 'memory-limit') {
164168
// symfony/console does not accept -1 as value without assign
165169
$workerCommandOptions[] = self::OPTION_DASHES . $mainCommandOptionName . '=' . \escapeshellarg($optionValue);

src/ValueObject/Configuration.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ final class Configuration
6868
*/
6969
private bool $reportingWithRealPath = \false;
7070
/**
71+
* @var string[]
7172
* @readonly
7273
*/
73-
private ?string $onlyRule = null;
74+
private array $onlyRules = [];
7475
/**
7576
* @readonly
7677
*/
@@ -104,10 +105,11 @@ final class Configuration
104105
/**
105106
* @param string[] $fileExtensions
106107
* @param string[] $paths
108+
* @param string[] $onlyRules
107109
* @param LevelOverflow[] $levelOverflows
108110
* @param string[] $filters
109111
*/
110-
public function __construct(bool $isDryRun = \false, bool $showProgressBar = \true, bool $shouldClearCache = \false, string $outputFormat = ConsoleOutputFormatter::NAME, array $fileExtensions = ['php'], array $paths = [], bool $showDiffs = \true, ?string $parallelPort = null, ?string $parallelIdentifier = null, bool $isParallel = \false, ?string $memoryLimit = null, bool $isDebug = \false, bool $reportingWithRealPath = \false, ?string $onlyRule = null, ?string $onlySuffix = null, array $levelOverflows = [], bool $showRulesSummary = \false, bool $isComposerBased = \false, bool $isPhpOnly = \false, array $filters = [], ?int $maxChanges = null)
112+
public function __construct(bool $isDryRun = \false, bool $showProgressBar = \true, bool $shouldClearCache = \false, string $outputFormat = ConsoleOutputFormatter::NAME, array $fileExtensions = ['php'], array $paths = [], bool $showDiffs = \true, ?string $parallelPort = null, ?string $parallelIdentifier = null, bool $isParallel = \false, ?string $memoryLimit = null, bool $isDebug = \false, bool $reportingWithRealPath = \false, array $onlyRules = [], ?string $onlySuffix = null, array $levelOverflows = [], bool $showRulesSummary = \false, bool $isComposerBased = \false, bool $isPhpOnly = \false, array $filters = [], ?int $maxChanges = null)
111113
{
112114
$this->isDryRun = $isDryRun;
113115
$this->showProgressBar = $showProgressBar;
@@ -122,7 +124,7 @@ public function __construct(bool $isDryRun = \false, bool $showProgressBar = \tr
122124
$this->memoryLimit = $memoryLimit;
123125
$this->isDebug = $isDebug;
124126
$this->reportingWithRealPath = $reportingWithRealPath;
125-
$this->onlyRule = $onlyRule;
127+
$this->onlyRules = $onlyRules;
126128
$this->onlySuffix = $onlySuffix;
127129
$this->levelOverflows = $levelOverflows;
128130
$this->showRulesSummary = $showRulesSummary;
@@ -163,9 +165,12 @@ public function getFileExtensions(): array
163165
Assert::notEmpty($this->fileExtensions);
164166
return $this->fileExtensions;
165167
}
166-
public function getOnlyRule(): ?string
168+
/**
169+
* @return string[]
170+
*/
171+
public function getOnlyRules(): array
167172
{
168-
return $this->onlyRule;
173+
return $this->onlyRules;
169174
}
170175
/**
171176
* @return string[]

0 commit comments

Comments
 (0)