Skip to content

Commit 0df929a

Browse files
committed
Updated Rector to commit de69d058258a2a6639a2d9b937a731a8665978d8
rectorphp/rector-src@de69d05 Add --rules-summary option to display applied rules summary with count (#7874)
1 parent a40b100 commit 0df929a

7 files changed

Lines changed: 54 additions & 4 deletions

File tree

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 = 'f2be385b38e514ea3d702aa4cd0f08cf98305703';
22+
public const PACKAGE_VERSION = 'de69d058258a2a6639a2d9b937a731a8665978d8';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2026-04-07 18:30:39';
27+
public const RELEASE_DATE = '2026-04-07 18:37:31';
2828
/**
2929
* @var int
3030
*/

src/ChangesReporting/Output/ConsoleOutputFormatter.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public function report(ProcessResult $processResult, Configuration $configuratio
4545
if ($configuration->shouldShowProgressBar() && $processResult->getFileDiffs() === []) {
4646
$this->symfonyStyle->newLine();
4747
}
48+
if ($configuration->shouldShowRulesSummary()) {
49+
$this->reportRulesSummary($processResult, $configuration);
50+
}
4851
$message = $this->createSuccessMessage($processResult, $configuration);
4952
$this->symfonyStyle->success($message);
5053
}
@@ -101,6 +104,20 @@ private function reportErrors(array $errors, bool $absoluteFilePath): void
101104
$this->symfonyStyle->error($message);
102105
}
103106
}
107+
private function reportRulesSummary(ProcessResult $processResult, Configuration $configuration): void
108+
{
109+
$ruleApplicationCounts = $processResult->getRuleApplicationCounts();
110+
if ($ruleApplicationCounts === []) {
111+
return;
112+
}
113+
$verb = $configuration->isDryRun() ? 'would have been applied' : 'was applied';
114+
$this->symfonyStyle->section('Rules Summary');
115+
foreach ($ruleApplicationCounts as $ruleClass => $count) {
116+
$ruleShortClass = (string) Strings::after($ruleClass, '\\', -1);
117+
$this->symfonyStyle->writeln(sprintf(' * <info>%s</info> %s <comment>%d</comment> time%s', $ruleShortClass, $verb, $count, $count > 1 ? 's' : ''));
118+
}
119+
$this->symfonyStyle->newLine();
120+
}
104121
private function normalizePathsToRelativeWithLine(string $errorMessage): string
105122
{
106123
$regex = '#' . preg_quote(getcwd(), '#') . '/#';

src/Configuration/ConfigurationFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public function createFromInput(InputInterface $input): Configuration
6464
$memoryLimit = $this->resolveMemoryLimit($input);
6565
$isReportingWithRealPath = SimpleParameterProvider::provideBoolParameter(\Rector\Configuration\Option::ABSOLUTE_FILE_PATH);
6666
$levelOverflows = SimpleParameterProvider::provideArrayParameter(\Rector\Configuration\Option::LEVEL_OVERFLOWS);
67-
return new Configuration($isDryRun, $showProgressBar, $shouldClearCache, $outputFormat, $fileExtensions, $paths, $showDiffs, $parallelPort, $parallelIdentifier, $isParallel, $memoryLimit, $isDebug, $isReportingWithRealPath, $onlyRule, $onlySuffix, $levelOverflows);
67+
$showRulesSummary = (bool) $input->getOption(\Rector\Configuration\Option::RULES_SUMMARY);
68+
return new Configuration($isDryRun, $showProgressBar, $shouldClearCache, $outputFormat, $fileExtensions, $paths, $showDiffs, $parallelPort, $parallelIdentifier, $isParallel, $memoryLimit, $isDebug, $isReportingWithRealPath, $onlyRule, $onlySuffix, $levelOverflows, $showRulesSummary);
6869
}
6970
private function shouldShowProgressBar(InputInterface $input, string $outputFormat): bool
7071
{

src/Configuration/Option.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ final class Option
143143
* @var string
144144
*/
145145
public const XDEBUG = 'xdebug';
146+
/**
147+
* @var string
148+
*/
149+
public const RULES_SUMMARY = 'rules-summary';
146150
/**
147151
* @var string
148152
*/

src/Console/ProcessConfigureDecorator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ public static function decorate(Command $command): void
2727
$command->addOption(Option::PARALLEL_PORT, null, InputOption::VALUE_REQUIRED);
2828
$command->addOption(Option::PARALLEL_IDENTIFIER, null, InputOption::VALUE_REQUIRED);
2929
$command->addOption(Option::XDEBUG, null, InputOption::VALUE_NONE, 'Display xdebug output.');
30+
$command->addOption(Option::RULES_SUMMARY, null, InputOption::VALUE_NONE, 'Show summary of rules applied during the run.');
3031
}
3132
}

src/ValueObject/Configuration.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,16 @@ final class Configuration
8080
* @readonly
8181
*/
8282
private array $levelOverflows = [];
83+
/**
84+
* @readonly
85+
*/
86+
private bool $showRulesSummary = \false;
8387
/**
8488
* @param string[] $fileExtensions
8589
* @param string[] $paths
8690
* @param LevelOverflow[] $levelOverflows
8791
*/
88-
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 = [])
92+
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)
8993
{
9094
$this->isDryRun = $isDryRun;
9195
$this->showProgressBar = $showProgressBar;
@@ -103,6 +107,7 @@ public function __construct(bool $isDryRun = \false, bool $showProgressBar = \tr
103107
$this->onlyRule = $onlyRule;
104108
$this->onlySuffix = $onlySuffix;
105109
$this->levelOverflows = $levelOverflows;
110+
$this->showRulesSummary = $showRulesSummary;
106111
}
107112
public function isDryRun(): bool
108113
{
@@ -188,4 +193,8 @@ public function getBothSetAndRulesDuplicatedRegistrations(): array
188193
$ruleDuplicatedRegistrations = array_intersect($rootStandaloneRegisteredRules, $setRegisteredRules);
189194
return array_unique($ruleDuplicatedRegistrations);
190195
}
196+
public function shouldShowRulesSummary(): bool
197+
{
198+
return $this->showRulesSummary;
199+
}
191200
}

src/ValueObject/ProcessResult.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare (strict_types=1);
44
namespace Rector\ValueObject;
55

6+
use Rector\Contract\Rector\RectorInterface;
67
use Rector\ValueObject\Error\SystemError;
78
use Rector\ValueObject\Reporting\FileDiff;
89
use RectorPrefix202604\Webmozart\Assert\Assert;
@@ -62,4 +63,21 @@ public function getTotalChanged(): int
6263
{
6364
return $this->totalChanged;
6465
}
66+
/**
67+
* @return array<class-string<RectorInterface>, int>
68+
*/
69+
public function getRuleApplicationCounts(): array
70+
{
71+
$ruleCounts = [];
72+
foreach ($this->fileDiffs as $fileDiff) {
73+
foreach ($fileDiff->getRectorClasses() as $rectorClass) {
74+
if (!isset($ruleCounts[$rectorClass])) {
75+
$ruleCounts[$rectorClass] = 0;
76+
}
77+
++$ruleCounts[$rectorClass];
78+
}
79+
}
80+
arsort($ruleCounts);
81+
return $ruleCounts;
82+
}
6583
}

0 commit comments

Comments
 (0)