@@ -25,19 +25,17 @@ public function __construct(
25
25
private LocalIgnoresProcessor $ localIgnoresProcessor ,
26
26
private bool $ reportUnmatchedIgnoredErrors ,
27
27
private bool $ reportIgnoresWithoutIdentifiers ,
28
+ private bool $ reportIgnoresWithoutComments ,
28
29
)
29
30
{
30
31
}
31
32
32
33
public function finalize (AnalyserResult $ analyserResult , bool $ onlyFiles , bool $ debug ): FinalizerResult
33
34
{
34
- if (count ($ analyserResult ->getCollectedData ()) === 0 ) {
35
- return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutIdentifiersErrors ($ this ->mergeFilteredPhpErrors ($ analyserResult )), [], []);
36
- }
37
-
35
+ $ hasCollectedData = count ($ analyserResult ->getCollectedData ()) > 0 ;
38
36
$ hasInternalErrors = count ($ analyserResult ->getInternalErrors ()) > 0 || $ analyserResult ->hasReachedInternalErrorsCountLimit ();
39
- if ($ hasInternalErrors ) {
40
- return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutIdentifiersErrors ($ this ->mergeFilteredPhpErrors ($ analyserResult )), [], []);
37
+ if (! $ hasCollectedData || $ hasInternalErrors ) {
38
+ return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutCommentsErrors ( $ this -> addIgnoresWithoutIdentifiersErrors ($ this ->mergeFilteredPhpErrors ($ analyserResult) )), [], []);
41
39
}
42
40
43
41
$ nodeType = CollectedDataNode::class;
@@ -131,7 +129,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
131
129
$ allUnmatchedLineIgnores [$ file ] = $ localIgnoresProcessorResult ->getUnmatchedLineIgnores ();
132
130
}
133
131
134
- return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutIdentifiersErrors (new AnalyserResult (
132
+ return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutCommentsErrors ( $ this -> addIgnoresWithoutIdentifiersErrors (new AnalyserResult (
135
133
array_merge ($ errors , $ analyserResult ->getFilteredPhpErrors ()),
136
134
[],
137
135
$ analyserResult ->getAllPhpErrors (),
@@ -144,7 +142,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
144
142
$ analyserResult ->getExportedNodes (),
145
143
$ analyserResult ->hasReachedInternalErrorsCountLimit (),
146
144
$ analyserResult ->getPeakMemoryUsageBytes (),
147
- )), $ collectorErrors , $ locallyIgnoredCollectorErrors );
145
+ ))) , $ collectorErrors , $ locallyIgnoredCollectorErrors );
148
146
}
149
147
150
148
private function mergeFilteredPhpErrors (AnalyserResult $ analyserResult ): AnalyserResult
@@ -200,7 +198,7 @@ private function addUnmatchedIgnoredErrors(
200
198
201
199
foreach ($ identifiers as $ identifier ) {
202
200
$ errors [] = (new Error (
203
- sprintf ('No error with identifier %s is reported on line %d. ' , $ identifier , $ line ),
201
+ sprintf ('No error with identifier %s is reported on line %d. ' , $ identifier[ ' name ' ] , $ line ),
204
202
$ file ,
205
203
$ line ,
206
204
false ,
@@ -276,4 +274,56 @@ private function addIgnoresWithoutIdentifiersErrors(AnalyserResult $analyserResu
276
274
);
277
275
}
278
276
277
+ private function addIgnoresWithoutCommentsErrors (AnalyserResult $ analyserResult ): AnalyserResult
278
+ {
279
+ if (!$ this ->reportIgnoresWithoutComments ) {
280
+ return $ analyserResult ;
281
+ }
282
+
283
+ $ errors = $ analyserResult ->getUnorderedErrors ();
284
+ foreach ($ analyserResult ->getLinesToIgnore () as $ file => $ data ) {
285
+ foreach ($ data as $ ignoredFile => $ lines ) {
286
+ if ($ ignoredFile !== $ file ) {
287
+ continue ;
288
+ }
289
+
290
+ foreach ($ lines as $ line => $ identifiers ) {
291
+ if ($ identifiers === null ) {
292
+ continue ;
293
+ }
294
+
295
+ foreach ($ identifiers as $ identifier ) {
296
+ ['name ' => $ name , 'comment ' => $ comment ] = $ identifier ;
297
+ if ($ comment !== null ) {
298
+ continue ;
299
+ }
300
+
301
+ $ errors [] = (new Error (
302
+ sprintf ('Ignore with identifier %s has no comment. ' , $ name ),
303
+ $ file ,
304
+ $ line ,
305
+ false ,
306
+ $ file ,
307
+ ))->withIdentifier ('ignore.noComment ' );
308
+ }
309
+ }
310
+ }
311
+ }
312
+
313
+ return new AnalyserResult (
314
+ $ errors ,
315
+ $ analyserResult ->getFilteredPhpErrors (),
316
+ $ analyserResult ->getAllPhpErrors (),
317
+ $ analyserResult ->getLocallyIgnoredErrors (),
318
+ $ analyserResult ->getLinesToIgnore (),
319
+ $ analyserResult ->getUnmatchedLineIgnores (),
320
+ $ analyserResult ->getInternalErrors (),
321
+ $ analyserResult ->getCollectedData (),
322
+ $ analyserResult ->getDependencies (),
323
+ $ analyserResult ->getExportedNodes (),
324
+ $ analyserResult ->hasReachedInternalErrorsCountLimit (),
325
+ $ analyserResult ->getPeakMemoryUsageBytes (),
326
+ );
327
+ }
328
+
279
329
}
0 commit comments