-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathProcessResult.php
More file actions
82 lines (68 loc) · 1.96 KB
/
ProcessResult.php
File metadata and controls
82 lines (68 loc) · 1.96 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
<?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
*/
public function __construct(
private array $systemErrors,
private readonly array $fileDiffs,
private readonly int $totalChanged
) {
Assert::allIsInstanceOf($systemErrors, SystemError::class);
Assert::allIsInstanceOf($fileDiffs, FileDiff::class);
}
/**
* @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];
}
public function getTotalChanged(): int
{
return $this->totalChanged;
}
/**
* @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;
}
}