Repository navigation
Expand file tree
/
Copy pathDeprecatedRulesReporter.php
More file actions
77 lines (65 loc) · 2.6 KB
/
Copy pathDeprecatedRulesReporter.php
File metadata and controls
77 lines (65 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
declare(strict_types=1);
namespace Rector\Reporting;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Contract\Rector\RectorInterface;
use Rector\PhpParser\Node\FileNode;
use ReflectionMethod;
use Symfony\Component\Console\Style\SymfonyStyle;
final readonly class DeprecatedRulesReporter
{
/**
* @param RectorInterface[] $rectors
*/
public function __construct(
private SymfonyStyle $symfonyStyle,
private array $rectors
) {
}
public function reportDeprecatedRules(): void
{
/** @var string[] $registeredRectorRules */
$registeredRectorRules = SimpleParameterProvider::provideArrayParameter(Option::REGISTERED_RECTOR_RULES);
foreach ($registeredRectorRules as $registeredRectorRule) {
if (! is_a($registeredRectorRule, DeprecatedInterface::class, true)) {
continue;
}
$this->symfonyStyle->warning(
sprintf(
'Registered rule "%s" is deprecated and will be removed. Upgrade your config to use another rule or remove it',
$registeredRectorRule
)
);
}
}
public function reportDeprecatedSkippedRules(): void
{
/** @var string[] $skippedRectorRules */
$skippedRectorRules = SimpleParameterProvider::provideArrayParameter(Option::SKIPPED_RECTOR_RULES);
foreach ($skippedRectorRules as $skippedRectorRule) {
if (! is_a($skippedRectorRule, DeprecatedInterface::class, true)) {
continue;
}
$this->symfonyStyle->warning(sprintf('Skipped rule "%s" is deprecated', $skippedRectorRule));
}
}
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
));
}
}
}
}