|
4 | 4 |
|
5 | 5 | namespace Rector\Reporting; |
6 | 6 |
|
| 7 | +use Rector\PhpParser\Enum\NodeGroup; |
7 | 8 | use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; |
8 | 9 | use Rector\Configuration\Option; |
9 | 10 | use Rector\Configuration\Parameter\SimpleParameterProvider; |
| 11 | +use Rector\Contract\PhpParser\Node\StmtsAwareInterface; |
| 12 | +use Rector\Contract\Rector\RectorInterface; |
10 | 13 | use Symfony\Component\Console\Style\SymfonyStyle; |
11 | 14 |
|
12 | 15 | final readonly class DeprecatedRulesReporter |
13 | 16 | { |
| 17 | + /** |
| 18 | + * @param RectorInterface[] $rectors |
| 19 | + */ |
14 | 20 | public function __construct( |
15 | | - private SymfonyStyle $symfonyStyle |
| 21 | + private SymfonyStyle $symfonyStyle, |
| 22 | + private array $rectors |
16 | 23 | ) { |
17 | 24 | } |
18 | 25 |
|
@@ -48,4 +55,33 @@ public function reportDeprecatedSkippedRules(): void |
48 | 55 | $this->symfonyStyle->warning(sprintf('Skipped rule "%s" is deprecated', $skippedRectorRule)); |
49 | 56 | } |
50 | 57 | } |
| 58 | + |
| 59 | + public function reportDeprecatedNodeTypes(): void |
| 60 | + { |
| 61 | + // helper property to avoid reporting multiple times |
| 62 | + static $reportedClasses = []; |
| 63 | + |
| 64 | + foreach ($this->rectors as $rector) { |
| 65 | + if (! in_array(StmtsAwareInterface::class, $rector->getNodeTypes())) { |
| 66 | + continue; |
| 67 | + } |
| 68 | + |
| 69 | + // already reported, skip |
| 70 | + if (in_array($rector::class, $reportedClasses, true)) { |
| 71 | + continue; |
| 72 | + } |
| 73 | + |
| 74 | + $reportedClasses[] = $rector::class; |
| 75 | + |
| 76 | + $this->symfonyStyle->warning(sprintf( |
| 77 | + 'Rector rule "%s" uses StmtsAwareInterface that is now deprecated.%sUse "%s::%s" instead.%sSee %s for more', |
| 78 | + $rector::class, |
| 79 | + PHP_EOL, |
| 80 | + NodeGroup::class, |
| 81 | + 'STMTS_AWARE', |
| 82 | + PHP_EOL . PHP_EOL, |
| 83 | + 'https://github.com/rectorphp/rector-src/pull/7679' |
| 84 | + )); |
| 85 | + } |
| 86 | + } |
51 | 87 | } |
0 commit comments