Repository navigation
Expand file tree
/
Copy pathDeprecatedRulesReporter.php
More file actions
97 lines (79 loc) · 3.29 KB
/
Copy pathDeprecatedRulesReporter.php
File metadata and controls
97 lines (79 loc) · 3.29 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
declare(strict_types=1);
namespace Rector\Reporting;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Symfony\Component\Console\Style\SymfonyStyle;
final readonly class DeprecatedRulesReporter
{
public function __construct(
private SymfonyStyle $symfonyStyle
) {
}
public function reportDeprecatedRules(): int
{
/** @var string[] $registeredRectorRules */
$registeredRectorRules = SimpleParameterProvider::provideArrayParameter(Option::REGISTERED_RECTOR_RULES);
$reportedCount = 0;
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
)
);
++$reportedCount;
}
return $reportedCount;
}
public function reportDeprecatedSkippedRules(): int
{
/** @var string[] $skippedRectorRules */
$skippedRectorRules = SimpleParameterProvider::provideArrayParameter(Option::SKIPPED_RECTOR_RULES);
$reportedCount = 0;
foreach ($skippedRectorRules as $skippedRectorRule) {
if (! is_a($skippedRectorRule, DeprecatedInterface::class, true)) {
continue;
}
$this->symfonyStyle->warning(sprintf('Skipped rule "%s" is deprecated', $skippedRectorRule));
++$reportedCount;
}
return $reportedCount;
}
public function reportDeprecatedAttributesSetsArgs(): int
{
/** @var string[] $deprecatedAttributesSetsArgs */
$deprecatedAttributesSetsArgs = SimpleParameterProvider::provideArrayParameter(
Option::DEPRECATED_ATTRIBUTES_SETS_ARGS
);
$reportedCount = 0;
foreach (array_unique($deprecatedAttributesSetsArgs) as $deprecatedAttributesSetsArg) {
$this->symfonyStyle->warning(sprintf(
'The "->withAttributesSets(%s: true)" argument is deprecated and no longer applied. It is already included in the "symfony: true" argument, use it instead.',
$deprecatedAttributesSetsArg
));
++$reportedCount;
}
return $reportedCount;
}
public function reportDeprecatedComposerBasedArgs(): int
{
/** @var string[] $deprecatedComposerBasedArgs */
$deprecatedComposerBasedArgs = SimpleParameterProvider::provideArrayParameter(
Option::DEPRECATED_COMPOSER_BASED_ARGS
);
$reportedCount = 0;
foreach (array_unique($deprecatedComposerBasedArgs) as $deprecatedComposerBasedArg) {
$this->symfonyStyle->warning(sprintf(
'The "->withComposerBased(%s: true)" argument is deprecated and no longer applied. It only added named args to 2 methods of a single package, register the rule directly if needed.',
$deprecatedComposerBasedArg
));
++$reportedCount;
}
return $reportedCount;
}
}