@@ -24,19 +24,20 @@ public function __construct(
2424 private ScopeFactory $ scopeFactory ,
2525 private LocalIgnoresProcessor $ localIgnoresProcessor ,
2626 private bool $ reportUnmatchedIgnoredErrors ,
27+ private bool $ reportIgnoresWithoutIdentifiers ,
2728 )
2829 {
2930 }
3031
3132 public function finalize (AnalyserResult $ analyserResult , bool $ onlyFiles , bool $ debug ): FinalizerResult
3233 {
3334 if (count ($ analyserResult ->getCollectedData ()) === 0 ) {
34- return $ this ->addUnmatchedIgnoredErrors ($ this ->mergeFilteredPhpErrors ($ analyserResult ), [], []);
35+ return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutIdentifiersErrors ( $ this -> mergeFilteredPhpErrors ($ analyserResult) ), [], []);
3536 }
3637
3738 $ hasInternalErrors = count ($ analyserResult ->getInternalErrors ()) > 0 || $ analyserResult ->hasReachedInternalErrorsCountLimit ();
3839 if ($ hasInternalErrors ) {
39- return $ this ->addUnmatchedIgnoredErrors ($ this ->mergeFilteredPhpErrors ($ analyserResult ), [], []);
40+ return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutIdentifiersErrors ( $ this -> mergeFilteredPhpErrors ($ analyserResult) ), [], []);
4041 }
4142
4243 $ nodeType = CollectedDataNode::class;
@@ -130,7 +131,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
130131 $ allUnmatchedLineIgnores [$ file ] = $ localIgnoresProcessorResult ->getUnmatchedLineIgnores ();
131132 }
132133
133- return $ this ->addUnmatchedIgnoredErrors (new AnalyserResult (
134+ return $ this ->addUnmatchedIgnoredErrors ($ this -> addIgnoresWithoutIdentifiersErrors ( new AnalyserResult (
134135 array_merge ($ errors , $ analyserResult ->getFilteredPhpErrors ()),
135136 [],
136137 $ analyserResult ->getAllPhpErrors (),
@@ -143,7 +144,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
143144 $ analyserResult ->getExportedNodes (),
144145 $ analyserResult ->hasReachedInternalErrorsCountLimit (),
145146 $ analyserResult ->getPeakMemoryUsageBytes (),
146- ), $ collectorErrors , $ locallyIgnoredCollectorErrors );
147+ )) , $ collectorErrors , $ locallyIgnoredCollectorErrors );
147148 }
148149
149150 private function mergeFilteredPhpErrors (AnalyserResult $ analyserResult ): AnalyserResult
@@ -230,4 +231,49 @@ private function addUnmatchedIgnoredErrors(
230231 );
231232 }
232233
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+
233279}
0 commit comments