|
22 | 22 | use Rector\StaticReflection\DynamicSourceLocatorDecorator; |
23 | 23 | use Rector\Util\MemoryLimiter; |
24 | 24 | use Rector\ValueObject\Configuration; |
| 25 | +use Rector\ValueObject\Configuration\LevelOverflow; |
25 | 26 | use Rector\ValueObject\ProcessResult; |
26 | 27 | use Symfony\Component\Console\Application; |
27 | 28 | use Symfony\Component\Console\Command\Command; |
@@ -101,18 +102,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
101 | 102 |
|
102 | 103 | // 0. warn about too high levels |
103 | 104 | foreach ($configuration->getLevelOverflows() as $levelOverflow) { |
104 | | - $suggestedSetMethod = PHP_VERSION_ID >= 80000 ? sprintf( |
105 | | - '->withPreparedSets(%s: true)', |
106 | | - $levelOverflow->getSuggestedRuleset() |
107 | | - ) : sprintf('->withSets(SetList::%s)', $levelOverflow->getSuggestedSetListConstant()); |
| 105 | + $this->reportLevelOverflow($levelOverflow); |
| 106 | + } |
108 | 107 |
|
| 108 | + // 0. warn about rules registered in both withRules() and sets to avoid bloated rector.php configs |
| 109 | + $setAndRulesDuplicatedRegistrations = $configuration->getBothSetAndRulesDuplicatedRegistrations(); |
| 110 | + if ($setAndRulesDuplicatedRegistrations !== []) { |
109 | 111 | $this->symfonyStyle->warning(sprintf( |
110 | | - 'The "->%s()" level contains only %d rules, but you set level to %d.%sYou are using the full set now! Time to switch to more efficient "%s".', |
111 | | - $levelOverflow->getConfigurationName(), |
112 | | - $levelOverflow->getRuleCount(), |
113 | | - $levelOverflow->getLevel(), |
114 | | - PHP_EOL, |
115 | | - $suggestedSetMethod, |
| 112 | + 'These rules are registered in both sets and "withRules()". Remove them from "withRules()" to avoid duplications: %s* %s', |
| 113 | + PHP_EOL . PHP_EOL, |
| 114 | + implode(' * ', $setAndRulesDuplicatedRegistrations) . PHP_EOL |
116 | 115 | )); |
117 | 116 | } |
118 | 117 |
|
@@ -225,4 +224,21 @@ private function reportLoadedComposerBasedSets(): void |
225 | 224 | $this->symfonyStyle->writeln('[info] Sets loaded based on installed packages:'); |
226 | 225 | $this->symfonyStyle->listing($composerBasedSets); |
227 | 226 | } |
| 227 | + |
| 228 | + private function reportLevelOverflow(LevelOverflow $levelOverflow): void |
| 229 | + { |
| 230 | + $suggestedSetMethod = PHP_VERSION_ID >= 80000 ? sprintf( |
| 231 | + '->withPreparedSets(%s: true)', |
| 232 | + $levelOverflow->getSuggestedRuleset() |
| 233 | + ) : sprintf('->withSets(SetList::%s)', $levelOverflow->getSuggestedSetListConstant()); |
| 234 | + |
| 235 | + $this->symfonyStyle->warning(sprintf( |
| 236 | + 'The "->%s()" level contains only %d rules, but you set level to %d.%sYou are using the full set now! Time to switch to more efficient "%s".', |
| 237 | + $levelOverflow->getConfigurationName(), |
| 238 | + $levelOverflow->getRuleCount(), |
| 239 | + $levelOverflow->getLevel(), |
| 240 | + PHP_EOL, |
| 241 | + $suggestedSetMethod, |
| 242 | + )); |
| 243 | + } |
228 | 244 | } |
0 commit comments