Repository navigation
Expand file tree
/
Copy pathProcessResult.php
More file actions
107 lines (90 loc) · 2.69 KB
/
Copy pathProcessResult.php
File metadata and controls
107 lines (90 loc) · 2.69 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
<?php
declare(strict_types=1);
namespace Rector\ValueObject;
use Rector\Contract\Rector\RectorInterface;
use Rector\ValueObject\Error\SystemError;
use Rector\ValueObject\Reporting\FileDiff;
use Webmozart\Assert\Assert;
final class ProcessResult
{
/**
* @param SystemError[] $systemErrors
* @param FileDiff[] $fileDiffs
* @param string[] $usedSkips
*/
public function __construct(
private array $systemErrors,
private readonly array $fileDiffs,
private readonly int $totalChanged,
private array $usedSkips = []
) {
Assert::allIsInstanceOf($systemErrors, SystemError::class);
Assert::allIsInstanceOf($fileDiffs, FileDiff::class);
Assert::allString($usedSkips);
}
/**
* @return SystemError[]
*/
public function getSystemErrors(): array
{
return $this->systemErrors;
}
/**
* @return FileDiff[]
*/
public function getFileDiffs(bool $onlyWithChanges = true): array
{
if ($onlyWithChanges) {
return array_filter($this->fileDiffs, fn (FileDiff $fileDiff): bool => $fileDiff->getDiff() !== '');
}
return $this->fileDiffs;
}
/**
* @param SystemError[] $systemErrors
*/
public function addSystemErrors(array $systemErrors): void
{
Assert::allIsInstanceOf($systemErrors, SystemError::class);
$this->systemErrors = [...$this->systemErrors, ...$systemErrors];
}
/**
* Path-only skips are matched while finding files in the main process, but parallel runs build
* their result from worker processes only. Merge those main-process marks back in, or they would
* be wrongly reported as unused.
*
* @param string[] $usedSkips
*/
public function addUsedSkips(array $usedSkips): void
{
Assert::allString($usedSkips);
$this->usedSkips = array_values(array_unique([...$this->usedSkips, ...$usedSkips]));
}
public function getTotalChanged(): int
{
return $this->totalChanged;
}
/**
* @return string[]
*/
public function getUsedSkips(): array
{
return $this->usedSkips;
}
/**
* @return array<class-string<RectorInterface>, int>
*/
public function getRuleApplicationCounts(): array
{
$ruleCounts = [];
foreach ($this->fileDiffs as $fileDiff) {
foreach ($fileDiff->getRectorClasses() as $rectorClass) {
if (! isset($ruleCounts[$rectorClass])) {
$ruleCounts[$rectorClass] = 0;
}
++$ruleCounts[$rectorClass];
}
}
arsort($ruleCounts);
return $ruleCounts;
}
}