@@ -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 (),
@@ -144,7 +145,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
144145 $ analyserResult ->getExportedNodes (),
145146 $ analyserResult ->hasReachedInternalErrorsCountLimit (),
146147 $ analyserResult ->getPeakMemoryUsageBytes (),
147- ), $ collectorErrors , $ locallyIgnoredCollectorErrors );
148+ )) , $ collectorErrors , $ locallyIgnoredCollectorErrors );
148149 }
149150
150151 private function mergeFilteredPhpErrors (AnalyserResult $ analyserResult ): AnalyserResult
@@ -233,4 +234,50 @@ private function addUnmatchedIgnoredErrors(
233234 );
234235 }
235236
237+ private function addIgnoresWithoutIdentifiersErrors (AnalyserResult $ analyserResult ): AnalyserResult
238+ {
239+ if (!$ this ->reportIgnoresWithoutIdentifiers ) {
240+ return $ analyserResult ;
241+ }
242+
243+ $ errors = $ analyserResult ->getUnorderedErrors ();
244+ foreach ($ analyserResult ->getLinesToIgnore () as $ file => $ data ) {
245+ foreach ($ data as $ ignoredFile => $ lines ) {
246+ if ($ ignoredFile !== $ file ) {
247+ continue ;
248+ }
249+
250+ foreach ($ lines as $ line => $ identifiers ) {
251+ if ($ identifiers !== null ) {
252+ continue ;
253+ }
254+
255+ $ errors [] = (new Error (
256+ sprintf ('Error is ignored with no identifiers on line %d. ' , $ line ),
257+ $ file ,
258+ $ line ,
259+ false ,
260+ $ file ,
261+ ))->withIdentifier ('ignore.noIdentifier ' );
262+ }
263+ }
264+ }
265+
266+ return new AnalyserResult (
267+ $ errors ,
268+ $ analyserResult ->getFilteredPhpErrors (),
269+ $ analyserResult ->getAllPhpErrors (),
270+ $ analyserResult ->getLocallyIgnoredErrors (),
271+ $ analyserResult ->getLinesToIgnore (),
272+ $ analyserResult ->getUnmatchedLineIgnores (),
273+ $ analyserResult ->getInternalErrors (),
274+ $ analyserResult ->getCollectedData (),
275+ $ analyserResult ->getDependencies (),
276+ $ analyserResult ->getUsedTraitDependencies (),
277+ $ analyserResult ->getExportedNodes (),
278+ $ analyserResult ->hasReachedInternalErrorsCountLimit (),
279+ $ analyserResult ->getPeakMemoryUsageBytes (),
280+ );
281+ }
282+
236283}
0 commit comments