@@ -28,19 +28,21 @@ public function __construct(
2828		private  LocalIgnoresProcessor   $ localIgnoresProcessor ,
2929		#[AutowiredParameter]
3030		private  bool  $ reportUnmatchedIgnoredErrors ,
31+ 		#[AutowiredParameter]
32+ 		private  bool  $ reportIgnoresWithoutIdentifiers ,
3133	)
3234	{
3335	}
3436
3537	public  function  finalize (AnalyserResult   $ analyserResult , bool  $ onlyFiles , bool  $ debug ): FinalizerResult 
3638	{
3739		if  (count ($ analyserResult ->getCollectedData ()) === 0 ) {
38- 			return  $ this  ->addUnmatchedIgnoredErrors ($ this  ->mergeFilteredPhpErrors ($ analyserResult ), [], []);
40+ 			return  $ this  ->addUnmatchedIgnoredErrors ($ this  ->addIgnoresWithoutIdentifiersErrors ( $ this -> mergeFilteredPhpErrors ($ analyserResult) ), [], []);
3941		}
4042
4143		$ hasInternalErrors  = count ($ analyserResult ->getInternalErrors ()) > 0  || $ analyserResult ->hasReachedInternalErrorsCountLimit ();
4244		if  ($ hasInternalErrors ) {
43- 			return  $ this  ->addUnmatchedIgnoredErrors ($ this  ->mergeFilteredPhpErrors ($ analyserResult ), [], []);
45+ 			return  $ this  ->addUnmatchedIgnoredErrors ($ this  ->addIgnoresWithoutIdentifiersErrors ( $ this -> mergeFilteredPhpErrors ($ analyserResult) ), [], []);
4446		}
4547
4648		$ nodeType  = CollectedDataNode::class;
@@ -134,7 +136,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
134136			$ allUnmatchedLineIgnores [$ file ] = $ localIgnoresProcessorResult ->getUnmatchedLineIgnores ();
135137		}
136138
137- 		return  $ this  ->addUnmatchedIgnoredErrors (new  AnalyserResult (
139+ 		return  $ this  ->addUnmatchedIgnoredErrors ($ this -> addIgnoresWithoutIdentifiersErrors ( new  AnalyserResult (
138140			array_merge ($ errors , $ analyserResult ->getFilteredPhpErrors ()),
139141			[],
140142			$ analyserResult ->getAllPhpErrors (),
@@ -148,7 +150,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
148150			$ analyserResult ->getExportedNodes (),
149151			$ analyserResult ->hasReachedInternalErrorsCountLimit (),
150152			$ analyserResult ->getPeakMemoryUsageBytes (),
151- 		), $ collectorErrors , $ locallyIgnoredCollectorErrors );
153+ 		)) , $ collectorErrors , $ locallyIgnoredCollectorErrors );
152154	}
153155
154156	private  function  mergeFilteredPhpErrors (AnalyserResult   $ analyserResult ): AnalyserResult 
@@ -237,4 +239,50 @@ private function addUnmatchedIgnoredErrors(
237239		);
238240	}
239241
242+ 	private  function  addIgnoresWithoutIdentifiersErrors (AnalyserResult   $ analyserResult ): AnalyserResult 
243+ 	{
244+ 		if  (!$ this  ->reportIgnoresWithoutIdentifiers ) {
245+ 			return  $ analyserResult ;
246+ 		}
247+ 
248+ 		$ errors  = $ analyserResult ->getUnorderedErrors ();
249+ 		foreach  ($ analyserResult ->getLinesToIgnore () as  $ file  => $ data ) {
250+ 			foreach  ($ data  as  $ ignoredFile  => $ lines ) {
251+ 				if  ($ ignoredFile  !== $ file ) {
252+ 					continue ;
253+ 				}
254+ 
255+ 				foreach  ($ lines  as  $ line  => $ identifiers ) {
256+ 					if  ($ identifiers  !== null ) {
257+ 						continue ;
258+ 					}
259+ 
260+ 					$ errors [] = (new  Error (
261+ 						sprintf ('Error is ignored with no identifiers on line %d. ' , $ line ),
262+ 						$ file ,
263+ 						$ line ,
264+ 						false ,
265+ 						$ file ,
266+ 					))->withIdentifier ('ignore.noIdentifier ' );
267+ 				}
268+ 			}
269+ 		}
270+ 
271+ 		return  new  AnalyserResult (
272+ 			$ errors ,
273+ 			$ analyserResult ->getFilteredPhpErrors (),
274+ 			$ analyserResult ->getAllPhpErrors (),
275+ 			$ analyserResult ->getLocallyIgnoredErrors (),
276+ 			$ analyserResult ->getLinesToIgnore (),
277+ 			$ analyserResult ->getUnmatchedLineIgnores (),
278+ 			$ analyserResult ->getInternalErrors (),
279+ 			$ analyserResult ->getCollectedData (),
280+ 			$ analyserResult ->getDependencies (),
281+ 			$ analyserResult ->getUsedTraitDependencies (),
282+ 			$ analyserResult ->getExportedNodes (),
283+ 			$ analyserResult ->hasReachedInternalErrorsCountLimit (),
284+ 			$ analyserResult ->getPeakMemoryUsageBytes (),
285+ 		);
286+ 	}
287+ 
240288}
0 commit comments