15
15
use PHPStan \Parser \Parser ;
16
16
use PHPStan \Parser \ParserErrorsException ;
17
17
use PHPStan \Rules \Registry as RuleRegistry ;
18
- use function array_key_exists ;
19
18
use function array_keys ;
20
19
use function array_merge ;
21
20
use function array_unique ;
22
21
use function array_values ;
23
22
use function count ;
24
23
use function error_reporting ;
25
24
use function get_class ;
26
- use function is_array ;
27
25
use function is_dir ;
28
26
use function is_file ;
29
27
use function restore_error_handler ;
@@ -43,6 +41,7 @@ public function __construct(
43
41
private Parser $ parser ,
44
42
private DependencyResolver $ dependencyResolver ,
45
43
private RuleErrorTransformer $ ruleErrorTransformer ,
44
+ private LocalIgnoresProcessor $ localIgnoresProcessor ,
46
45
private bool $ reportUnmatchedIgnoredErrors ,
47
46
)
48
47
{
@@ -176,69 +175,20 @@ public function analyseFile(
176
175
$ scope ,
177
176
$ nodeCallback ,
178
177
);
179
- foreach ($ temporaryFileErrors as $ tmpFileError ) {
180
- $ line = $ tmpFileError ->getLine ();
181
- if (
182
- $ line !== null
183
- && $ tmpFileError ->canBeIgnored ()
184
- && array_key_exists ($ tmpFileError ->getFile (), $ linesToIgnore )
185
- && array_key_exists ($ line , $ linesToIgnore [$ tmpFileError ->getFile ()])
186
- ) {
187
- $ identifiers = $ linesToIgnore [$ tmpFileError ->getFile ()][$ line ];
188
- if ($ identifiers === null ) {
189
- $ locallyIgnoredErrors [] = $ tmpFileError ;
190
- unset($ unmatchedLineIgnores [$ tmpFileError ->getFile ()][$ line ]);
191
- continue ;
192
- }
193
-
194
- if ($ tmpFileError ->getIdentifier () === null ) {
195
- $ fileErrors [] = $ tmpFileError ;
196
- continue ;
197
- }
198
-
199
- foreach ($ identifiers as $ i => $ ignoredIdentifier ) {
200
- if ($ ignoredIdentifier !== $ tmpFileError ->getIdentifier ()) {
201
- continue ;
202
- }
203
-
204
- unset($ identifiers [$ i ]);
205
178
206
- if (count ($ identifiers ) > 0 ) {
207
- $ linesToIgnore [$ tmpFileError ->getFile ()][$ line ] = array_values ($ identifiers );
208
- } else {
209
- unset($ linesToIgnore [$ tmpFileError ->getFile ()][$ line ]);
210
- }
211
-
212
- if (
213
- array_key_exists ($ tmpFileError ->getFile (), $ unmatchedLineIgnores )
214
- && array_key_exists ($ line , $ unmatchedLineIgnores [$ tmpFileError ->getFile ()])
215
- ) {
216
- $ unmatchedIgnoredIdentifiers = $ unmatchedLineIgnores [$ tmpFileError ->getFile ()][$ line ];
217
- if (is_array ($ unmatchedIgnoredIdentifiers )) {
218
- foreach ($ unmatchedIgnoredIdentifiers as $ j => $ unmatchedIgnoredIdentifier ) {
219
- if ($ ignoredIdentifier !== $ unmatchedIgnoredIdentifier ) {
220
- continue ;
221
- }
222
-
223
- unset($ unmatchedIgnoredIdentifiers [$ j ]);
224
-
225
- if (count ($ unmatchedIgnoredIdentifiers ) > 0 ) {
226
- $ unmatchedLineIgnores [$ tmpFileError ->getFile ()][$ line ] = array_values ($ unmatchedIgnoredIdentifiers );
227
- } else {
228
- unset($ unmatchedLineIgnores [$ tmpFileError ->getFile ()][$ line ]);
229
- }
230
- break ;
231
- }
232
- }
233
- }
234
-
235
- $ locallyIgnoredErrors [] = $ tmpFileError ;
236
- continue 2 ;
237
- }
238
- }
239
-
240
- $ fileErrors [] = $ tmpFileError ;
179
+ $ localIgnoresProcessorResult = $ this ->localIgnoresProcessor ->process (
180
+ $ temporaryFileErrors ,
181
+ $ linesToIgnore ,
182
+ $ unmatchedLineIgnores ,
183
+ );
184
+ foreach ($ localIgnoresProcessorResult ->getFileErrors () as $ fileError ) {
185
+ $ fileErrors [] = $ fileError ;
186
+ }
187
+ foreach ($ localIgnoresProcessorResult ->getLocallyIgnoredErrors () as $ locallyIgnoredError ) {
188
+ $ locallyIgnoredErrors [] = $ locallyIgnoredError ;
241
189
}
190
+ $ linesToIgnore = $ localIgnoresProcessorResult ->getLinesToIgnore ();
191
+ $ unmatchedLineIgnores = $ localIgnoresProcessorResult ->getUnmatchedLineIgnores ();
242
192
243
193
if ($ this ->reportUnmatchedIgnoredErrors ) {
244
194
foreach ($ unmatchedLineIgnores as $ ignoredFile => $ lines ) {
0 commit comments