Repository navigation
Expand file tree
/
Copy pathMissConfigurationReporter.php
More file actions
111 lines (90 loc) · 3.93 KB
/
Copy pathMissConfigurationReporter.php
File metadata and controls
111 lines (90 loc) · 3.93 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
declare(strict_types=1);
namespace Rector\Reporting;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Configuration\VendorMissAnalyseGuard;
use Rector\PostRector\Contract\Rector\PostRectorInterface;
use Rector\ValueObject\ProcessResult;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* @see \Rector\Tests\Reporting\MissConfigurationReporterTest
*/
final readonly class MissConfigurationReporter
{
public function __construct(
private SymfonyStyle $symfonyStyle,
private VendorMissAnalyseGuard $vendorMissAnalyseGuard,
private UnusedSkipResolver $unusedSkipResolver,
) {
}
/**
* Reports skips configured via "->withSkip()" that never matched any element during the run.
* Enabled with "->reportUnusedSkips()".
*/
public function reportUnusedSkips(ProcessResult $processResult): void
{
$unusedSkips = $this->unusedSkipResolver->resolve($processResult);
if ($unusedSkips === []) {
return;
}
$this->symfonyStyle->warning(sprintf(
'%s never matched any element. You can remove %s from "->withSkip()"',
count($unusedSkips) > 1 ? 'These skips are unused, they' : 'This skip is unused, it',
count($unusedSkips) > 1 ? 'them' : 'it'
));
// add a blank line between items, so grouped rule skips stay visually separated
$spacedUnusedSkips = array_map(static fn (string $unusedSkip): string => $unusedSkip . "\n", $unusedSkips);
$this->symfonyStyle->listing($spacedUnusedSkips);
}
public function reportSkippedNeverRegisteredRules(): void
{
$registeredRules = SimpleParameterProvider::provideArrayParameter(Option::REGISTERED_RECTOR_RULES);
$skippedRules = SimpleParameterProvider::provideArrayParameter(Option::SKIPPED_RECTOR_RULES);
$neverRegisteredSkippedRules = array_unique(array_diff($skippedRules, $registeredRules));
// remove special PostRectorInterface rules, they are registered in a different way
$neverRegisteredSkippedRules = array_filter(
$neverRegisteredSkippedRules,
fn ($skippedRule): bool => ! is_a($skippedRule, PostRectorInterface::class, true)
);
if ($neverRegisteredSkippedRules === []) {
return;
}
$this->symfonyStyle->warning(sprintf(
'%s never registered. You can remove %s from "->withSkip()"',
count($neverRegisteredSkippedRules) > 1 ? 'These skipped rules are' : 'This skipped rule is',
count($neverRegisteredSkippedRules) > 1 ? 'them' : 'it'
));
$this->symfonyStyle->listing($neverRegisteredSkippedRules);
}
/**
* @param string[] $filePaths
*/
public function reportVendorInPaths(array $filePaths): void
{
if (! $this->vendorMissAnalyseGuard->isVendorAnalyzed($filePaths)) {
return;
}
$this->symfonyStyle->warning(sprintf(
'Rector has detected a "/vendor" directory in your configured paths. If this is Composer\'s vendor directory, this is not necessary as it will be autoloaded. Scanning the Composer /vendor directory will cause Rector to run much slower and possibly with errors.%sRemove "/vendor" from Rector paths and run again.',
"\n\n"
));
sleep(3);
}
public function reportStartWithShortOpenTag(): void
{
$files = SimpleParameterProvider::provideArrayParameter(Option::SKIPPED_START_WITH_SHORT_OPEN_TAG_FILES);
if ($files === []) {
return;
}
$suffix = count($files) > 1 ? 's were' : ' was';
$fileList = implode("\n", $files);
$this->symfonyStyle->warning(sprintf(
'The following file%s skipped as starting with short open tag. Migrate to long open PHP tag first: %s%s',
$suffix,
"\n\n",
$fileList
));
sleep(3);
}
}