Skip to content

Commit c9f45f7

Browse files
committed
warn about deprecated type
1 parent 53d0947 commit c9f45f7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Console/Command/ProcessCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
179179

180180
$outputFormatter->report($processResult, $configuration);
181181

182+
// 4. Deprecations reporter
182183
$this->deprecatedRulesReporter->reportDeprecatedRules();
183184
$this->deprecatedRulesReporter->reportDeprecatedSkippedRules();
184185
$this->deprecatedRulesReporter->reportDeprecatedNodeTypes();

src/Reporting/DeprecatedRulesReporter.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
1111
use Rector\Contract\Rector\RectorInterface;
1212
use Rector\PhpParser\Enum\NodeGroup;
13+
use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace;
14+
use Rector\PhpParser\Node\FileNode;
1315
use Symfony\Component\Console\Style\SymfonyStyle;
1416

1517
final readonly class DeprecatedRulesReporter
@@ -62,6 +64,11 @@ public function reportDeprecatedNodeTypes(): void
6264
static $reportedClasses = [];
6365

6466
foreach ($this->rectors as $rector) {
67+
if (in_array(FileWithoutNamespace::class, $rector->getNodeTypes(), true)) {
68+
$this->reportDeprecatedFileWithoutNamespace($rector);
69+
continue;
70+
}
71+
6572
if (! in_array(StmtsAwareInterface::class, $rector->getNodeTypes())) {
6673
continue;
6774
}
@@ -84,4 +91,16 @@ public function reportDeprecatedNodeTypes(): void
8491
));
8592
}
8693
}
94+
95+
private function reportDeprecatedFileWithoutNamespace(RectorInterface $rector): void
96+
{
97+
$this->symfonyStyle->warning(sprintf(
98+
'Node type "%s" is deprecated and will be removed. Use "%s" in the "%s" rule instead instead.%sSee %s for upgrade path',
99+
FileWithoutNamespace::class,
100+
FileNode::class,
101+
$rector::class,
102+
PHP_EOL . PHP_EOL,
103+
'https://github.com/rectorphp/rector-src/blob/main/UPGRADING.md'
104+
));
105+
}
87106
}

0 commit comments

Comments
 (0)