forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalIgnoresProcessor.php
More file actions
103 lines (88 loc) · 2.77 KB
/
LocalIgnoresProcessor.php
File metadata and controls
103 lines (88 loc) · 2.77 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
<?php declare(strict_types = 1);
namespace PHPStan\Analyser;
use PHPStan\DependencyInjection\AutowiredService;
use function array_key_exists;
use function array_values;
use function count;
use function is_array;
/**
* @phpstan-import-type LinesToIgnore from FileAnalyserResult
*/
#[AutowiredService]
final class LocalIgnoresProcessor
{
/**
* @param list<Error> $temporaryFileErrors
* @param LinesToIgnore $linesToIgnore
* @param LinesToIgnore $unmatchedLineIgnores
*/
public function process(
array $temporaryFileErrors,
array $linesToIgnore,
array $unmatchedLineIgnores,
): LocalIgnoresProcessorResult
{
$fileErrors = [];
$locallyIgnoredErrors = [];
foreach ($temporaryFileErrors as $tmpFileError) {
$line = $tmpFileError->getLine();
if (
$line !== null
&& $tmpFileError->canBeIgnored()
&& array_key_exists($tmpFileError->getFile(), $linesToIgnore)
&& array_key_exists($line, $linesToIgnore[$tmpFileError->getFile()])
) {
$identifiers = $linesToIgnore[$tmpFileError->getFile()][$line];
if ($identifiers === null) {
$locallyIgnoredErrors[] = $tmpFileError;
unset($unmatchedLineIgnores[$tmpFileError->getFile()][$line]);
continue;
}
if ($tmpFileError->getIdentifier() === null) {
$fileErrors[] = $tmpFileError;
continue;
}
foreach ($identifiers as $i => $ignoredIdentifier) {
if ($ignoredIdentifier['name'] !== $tmpFileError->getIdentifier()) {
continue;
}
unset($identifiers[$i]);
if (count($identifiers) > 0) {
$linesToIgnore[$tmpFileError->getFile()][$line] = array_values($identifiers);
} else {
unset($linesToIgnore[$tmpFileError->getFile()][$line]);
}
if (
array_key_exists($tmpFileError->getFile(), $unmatchedLineIgnores)
&& array_key_exists($line, $unmatchedLineIgnores[$tmpFileError->getFile()])
) {
$unmatchedIgnoredIdentifiers = $unmatchedLineIgnores[$tmpFileError->getFile()][$line];
if (is_array($unmatchedIgnoredIdentifiers)) {
foreach ($unmatchedIgnoredIdentifiers as $j => $unmatchedIgnoredIdentifier) {
if ($ignoredIdentifier['name'] !== $unmatchedIgnoredIdentifier['name']) {
continue;
}
unset($unmatchedIgnoredIdentifiers[$j]);
if (count($unmatchedIgnoredIdentifiers) > 0) {
$unmatchedLineIgnores[$tmpFileError->getFile()][$line] = array_values($unmatchedIgnoredIdentifiers);
} else {
unset($unmatchedLineIgnores[$tmpFileError->getFile()][$line]);
}
break;
}
}
}
$locallyIgnoredErrors[] = $tmpFileError;
continue 2;
}
}
$fileErrors[] = $tmpFileError;
}
return new LocalIgnoresProcessorResult(
$fileErrors,
$locallyIgnoredErrors,
$linesToIgnore,
$unmatchedLineIgnores,
);
}
}