Skip to content

Commit aec723a

Browse files
committed
[dx] warn about deprecated beforeTraverse() method once FileNode is ready
1 parent e39c3e1 commit aec723a

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

composer-dependency-analyser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// ensure use version ^3.2.0
1818
->ignoreErrorsOnPackage('composer/pcre', [ErrorType::UNUSED_DEPENDENCY])
1919

20+
->ignoreErrorsOnPath(__DIR__ . '/src/Reporting/DeprecatedRulesReporter.php', [ErrorType::UNKNOWN_CLASS])
21+
2022
->ignoreErrorsOnPaths([
2123
__DIR__ . '/stubs',
2224
__DIR__ . '/tests',

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ parameters:
160160
- src/Validation/RectorConfigValidator.php
161161
# for phpunit version check
162162
- src/Testing/PHPUnit/AbstractLazyTestCase.php
163+
# future node class exists check
164+
- src/Reporting/DeprecatedRulesReporter.php
163165

164166
# use of internal phpstan classes
165167
-

src/Console/Command/ProcessCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
182182
$this->deprecatedRulesReporter->reportDeprecatedRules();
183183
$this->deprecatedRulesReporter->reportDeprecatedSkippedRules();
184184
$this->deprecatedRulesReporter->reportDeprecatedNodeTypes();
185+
$this->deprecatedRulesReporter->reportDeprecatedRectorUnsupportedMethods();
185186

186187
$this->missConfigurationReporter->reportSkippedNeverRegisteredRules();
187188

src/Reporting/DeprecatedRulesReporter.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
namespace Rector\Reporting;
66

7+
use Rector\PhpParserNode\FileNode;
78
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
89
use Rector\Configuration\Option;
910
use Rector\Configuration\Parameter\SimpleParameterProvider;
1011
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
1112
use Rector\Contract\Rector\RectorInterface;
1213
use Rector\PhpParser\Enum\NodeGroup;
14+
use ReflectionMethod;
1315
use Symfony\Component\Console\Style\SymfonyStyle;
1416

1517
final readonly class DeprecatedRulesReporter
@@ -56,6 +58,25 @@ public function reportDeprecatedSkippedRules(): void
5658
}
5759
}
5860

61+
public function reportDeprecatedRectorUnsupportedMethods(): void
62+
{
63+
// to be added in related PR
64+
if (! class_exists(FileNode::class)) {
65+
return;
66+
}
67+
68+
foreach ($this->rectors as $rector) {
69+
$beforeTraverseMethodReflection = new ReflectionMethod($rector, 'beforeTraverse');
70+
if ($beforeTraverseMethodReflection->getDeclaringClass()->getName() === $rector::class) {
71+
$this->symfonyStyle->warning(sprintf(
72+
'Rector rule "%s" uses deprecated "beforeTraverse" method. It should not be used, as will be marked as final. Not part of RectorInterface contract. Use "%s" to hook into file-level changes instead.',
73+
$rector::class,
74+
FileNode::class
75+
));
76+
}
77+
}
78+
}
79+
5980
public function reportDeprecatedNodeTypes(): void
6081
{
6182
// helper property to avoid reporting multiple times

0 commit comments

Comments
 (0)