Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions composer-dependency-analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// ensure use version ^3.2.0
->ignoreErrorsOnPackage('composer/pcre', [ErrorType::UNUSED_DEPENDENCY])

->ignoreErrorsOnPath(__DIR__ . '/src/Reporting/DeprecatedRulesReporter.php', [ErrorType::UNKNOWN_CLASS])

->ignoreErrorsOnPaths([
__DIR__ . '/stubs',
__DIR__ . '/tests',
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ parameters:
- src/Validation/RectorConfigValidator.php
# for phpunit version check
- src/Testing/PHPUnit/AbstractLazyTestCase.php
# future node class exists check
- src/Reporting/DeprecatedRulesReporter.php

# use of internal phpstan classes
-
Expand Down
1 change: 1 addition & 0 deletions src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->deprecatedRulesReporter->reportDeprecatedRules();
$this->deprecatedRulesReporter->reportDeprecatedSkippedRules();
$this->deprecatedRulesReporter->reportDeprecatedNodeTypes();
$this->deprecatedRulesReporter->reportDeprecatedRectorUnsupportedMethods();

$this->missConfigurationReporter->reportSkippedNeverRegisteredRules();

Expand Down
21 changes: 21 additions & 0 deletions src/Reporting/DeprecatedRulesReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace Rector\Reporting;

use Rector\PhpParserNode\FileNode;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Contract\Rector\RectorInterface;
use Rector\PhpParser\Enum\NodeGroup;
use ReflectionMethod;
use Symfony\Component\Console\Style\SymfonyStyle;

final readonly class DeprecatedRulesReporter
Expand Down Expand Up @@ -56,6 +58,25 @@ public function reportDeprecatedSkippedRules(): void
}
}

public function reportDeprecatedRectorUnsupportedMethods(): void
{
// to be added in related PR
if (! class_exists(FileNode::class)) {
return;
}

foreach ($this->rectors as $rector) {
$beforeTraverseMethodReflection = new ReflectionMethod($rector, 'beforeTraverse');
if ($beforeTraverseMethodReflection->getDeclaringClass()->getName() === $rector::class) {
$this->symfonyStyle->warning(sprintf(
'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.',
$rector::class,
FileNode::class
));
}
}
}

public function reportDeprecatedNodeTypes(): void
{
// helper property to avoid reporting multiple times
Expand Down