@@ -25,19 +25,17 @@ public function __construct(
2525 private LocalIgnoresProcessor $ localIgnoresProcessor ,
2626 private bool $ reportUnmatchedIgnoredErrors ,
2727 private bool $ reportIgnoresWithoutIdentifiers ,
28+ private bool $ reportIgnoresWithoutComments ,
2829 )
2930 {
3031 }
3132
3233 public function finalize (AnalyserResult $ analyserResult , bool $ onlyFiles , bool $ debug ): FinalizerResult
3334 {
34- if (count ($ analyserResult ->getCollectedData ()) === 0 ) {
35- return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutIdentifiersErrors ($ this ->mergeFilteredPhpErrors ($ analyserResult )), [], []);
36- }
37-
35+ $ hasCollectedData = count ($ analyserResult ->getCollectedData ()) > 0 ;
3836 $ 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) )), [], []);
4139 }
4240
4341 $ nodeType = CollectedDataNode::class;
@@ -131,7 +129,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
131129 $ allUnmatchedLineIgnores [$ file ] = $ localIgnoresProcessorResult ->getUnmatchedLineIgnores ();
132130 }
133131
134- return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutIdentifiersErrors (new AnalyserResult (
132+ return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutCommentsErrors ( $ this -> addIgnoresWithoutIdentifiersErrors (new AnalyserResult (
135133 array_merge ($ errors , $ analyserResult ->getFilteredPhpErrors ()),
136134 [],
137135 $ analyserResult ->getAllPhpErrors (),
@@ -144,7 +142,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
144142 $ analyserResult ->getExportedNodes (),
145143 $ analyserResult ->hasReachedInternalErrorsCountLimit (),
146144 $ analyserResult ->getPeakMemoryUsageBytes (),
147- )), $ collectorErrors , $ locallyIgnoredCollectorErrors );
145+ ))) , $ collectorErrors , $ locallyIgnoredCollectorErrors );
148146 }
149147
150148 private function mergeFilteredPhpErrors (AnalyserResult $ analyserResult ): AnalyserResult
@@ -200,7 +198,7 @@ private function addUnmatchedIgnoredErrors(
200198
201199 foreach ($ identifiers as $ identifier ) {
202200 $ 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 ),
204202 $ file ,
205203 $ line ,
206204 false ,
@@ -276,4 +274,56 @@ private function addIgnoresWithoutIdentifiersErrors(AnalyserResult $analyserResu
276274 );
277275 }
278276
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+
279329}
0 commit comments