@@ -24,19 +24,20 @@ public function __construct(
24
24
private ScopeFactory $ scopeFactory ,
25
25
private LocalIgnoresProcessor $ localIgnoresProcessor ,
26
26
private bool $ reportUnmatchedIgnoredErrors ,
27
+ private bool $ reportIgnoresWithoutIdentifiers ,
27
28
)
28
29
{
29
30
}
30
31
31
32
public function finalize (AnalyserResult $ analyserResult , bool $ onlyFiles , bool $ debug ): FinalizerResult
32
33
{
33
34
if (count ($ analyserResult ->getCollectedData ()) === 0 ) {
34
- return $ this ->addUnmatchedIgnoredErrors ($ this ->mergeFilteredPhpErrors ($ analyserResult ), [], []);
35
+ return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutIdentifiersErrors ( $ this -> mergeFilteredPhpErrors ($ analyserResult) ), [], []);
35
36
}
36
37
37
38
$ hasInternalErrors = count ($ analyserResult ->getInternalErrors ()) > 0 || $ analyserResult ->hasReachedInternalErrorsCountLimit ();
38
39
if ($ hasInternalErrors ) {
39
- return $ this ->addUnmatchedIgnoredErrors ($ this ->mergeFilteredPhpErrors ($ analyserResult ), [], []);
40
+ return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutIdentifiersErrors ( $ this -> mergeFilteredPhpErrors ($ analyserResult) ), [], []);
40
41
}
41
42
42
43
$ nodeType = CollectedDataNode::class;
@@ -130,7 +131,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
130
131
$ allUnmatchedLineIgnores [$ file ] = $ localIgnoresProcessorResult ->getUnmatchedLineIgnores ();
131
132
}
132
133
133
- return $ this ->addUnmatchedIgnoredErrors (new AnalyserResult (
134
+ return $ this ->addUnmatchedIgnoredErrors ($ this -> addIgnoresWithoutIdentifiersErrors ( new AnalyserResult (
134
135
array_merge ($ errors , $ analyserResult ->getFilteredPhpErrors ()),
135
136
[],
136
137
$ analyserResult ->getAllPhpErrors (),
@@ -143,7 +144,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
143
144
$ analyserResult ->getExportedNodes (),
144
145
$ analyserResult ->hasReachedInternalErrorsCountLimit (),
145
146
$ analyserResult ->getPeakMemoryUsageBytes (),
146
- ), $ collectorErrors , $ locallyIgnoredCollectorErrors );
147
+ )) , $ collectorErrors , $ locallyIgnoredCollectorErrors );
147
148
}
148
149
149
150
private function mergeFilteredPhpErrors (AnalyserResult $ analyserResult ): AnalyserResult
@@ -230,4 +231,49 @@ private function addUnmatchedIgnoredErrors(
230
231
);
231
232
}
232
233
234
+ private function addIgnoresWithoutIdentifiersErrors (AnalyserResult $ analyserResult ): AnalyserResult
235
+ {
236
+ if (!$ this ->reportIgnoresWithoutIdentifiers ) {
237
+ return $ analyserResult ;
238
+ }
239
+
240
+ $ errors = $ analyserResult ->getUnorderedErrors ();
241
+ foreach ($ analyserResult ->getLinesToIgnore () as $ file => $ data ) {
242
+ foreach ($ data as $ ignoredFile => $ lines ) {
243
+ if ($ ignoredFile !== $ file ) {
244
+ continue ;
245
+ }
246
+
247
+ foreach ($ lines as $ line => $ identifiers ) {
248
+ if ($ identifiers !== null ) {
249
+ continue ;
250
+ }
251
+
252
+ $ errors [] = (new Error (
253
+ sprintf ('Error is ignored with no identifiers on line %d. ' , $ line ),
254
+ $ file ,
255
+ $ line ,
256
+ false ,
257
+ $ file ,
258
+ ))->withIdentifier ('ignore.noIdentifier ' );
259
+ }
260
+ }
261
+ }
262
+
263
+ return new AnalyserResult (
264
+ $ errors ,
265
+ $ analyserResult ->getFilteredPhpErrors (),
266
+ $ analyserResult ->getAllPhpErrors (),
267
+ $ analyserResult ->getLocallyIgnoredErrors (),
268
+ $ analyserResult ->getLinesToIgnore (),
269
+ $ analyserResult ->getUnmatchedLineIgnores (),
270
+ $ analyserResult ->getInternalErrors (),
271
+ $ analyserResult ->getCollectedData (),
272
+ $ analyserResult ->getDependencies (),
273
+ $ analyserResult ->getExportedNodes (),
274
+ $ analyserResult ->hasReachedInternalErrorsCountLimit (),
275
+ $ analyserResult ->getPeakMemoryUsageBytes (),
276
+ );
277
+ }
278
+
233
279
}
0 commit comments