@@ -28,19 +28,18 @@ public function __construct(
2828 private LocalIgnoresProcessor $ localIgnoresProcessor ,
2929 #[AutowiredParameter]
3030 private bool $ reportUnmatchedIgnoredErrors ,
31+ #[AutowiredParameter]
32+ private bool $ reportIgnoresWithoutComments ,
3133 )
3234 {
3335 }
3436
3537 public function finalize (AnalyserResult $ analyserResult , bool $ onlyFiles , bool $ debug ): FinalizerResult
3638 {
37- if (count ($ analyserResult ->getCollectedData ()) === 0 ) {
38- return $ this ->addUnmatchedIgnoredErrors ($ this ->mergeFilteredPhpErrors ($ analyserResult ), [], []);
39- }
40-
39+ $ hasCollectedData = count ($ analyserResult ->getCollectedData ()) > 0 ;
4140 $ hasInternalErrors = count ($ analyserResult ->getInternalErrors ()) > 0 || $ analyserResult ->hasReachedInternalErrorsCountLimit ();
42- if ($ hasInternalErrors ) {
43- return $ this ->addUnmatchedIgnoredErrors ($ this ->mergeFilteredPhpErrors ($ analyserResult ), [], []);
41+ if (! $ hasCollectedData || $ hasInternalErrors ) {
42+ return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutCommentErrors ( $ this -> mergeFilteredPhpErrors ($ analyserResult) ), [], []);
4443 }
4544
4645 $ nodeType = CollectedDataNode::class;
@@ -134,7 +133,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
134133 $ allUnmatchedLineIgnores [$ file ] = $ localIgnoresProcessorResult ->getUnmatchedLineIgnores ();
135134 }
136135
137- return $ this ->addUnmatchedIgnoredErrors (new AnalyserResult (
136+ return $ this ->addUnmatchedIgnoredErrors ($ this -> addIgnoresWithoutCommentErrors ( new AnalyserResult (
138137 unorderedErrors: array_merge ($ errors , $ analyserResult ->getFilteredPhpErrors ()),
139138 filteredPhpErrors: [],
140139 allPhpErrors: $ analyserResult ->getAllPhpErrors (),
@@ -148,7 +147,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
148147 exportedNodes: $ analyserResult ->getExportedNodes (),
149148 reachedInternalErrorsCountLimit: $ analyserResult ->hasReachedInternalErrorsCountLimit (),
150149 peakMemoryUsageBytes: $ analyserResult ->getPeakMemoryUsageBytes (),
151- ), $ collectorErrors , $ locallyIgnoredCollectorErrors );
150+ )) , $ collectorErrors , $ locallyIgnoredCollectorErrors );
152151 }
153152
154153 private function mergeFilteredPhpErrors (AnalyserResult $ analyserResult ): AnalyserResult
@@ -205,7 +204,7 @@ private function addUnmatchedIgnoredErrors(
205204
206205 foreach ($ identifiers as $ identifier ) {
207206 $ errors [] = (new Error (
208- sprintf ('No error with identifier %s is reported on line %d. ' , $ identifier , $ line ),
207+ sprintf ('No error with identifier %s is reported on line %d. ' , $ identifier[ ' name ' ] , $ line ),
209208 $ file ,
210209 $ line ,
211210 false ,
@@ -237,4 +236,57 @@ private function addUnmatchedIgnoredErrors(
237236 );
238237 }
239238
239+ private function addIgnoresWithoutCommentErrors (AnalyserResult $ analyserResult ): AnalyserResult
240+ {
241+ if (!$ this ->reportIgnoresWithoutComments ) {
242+ return $ analyserResult ;
243+ }
244+
245+ $ errors = $ analyserResult ->getUnorderedErrors ();
246+ foreach ($ analyserResult ->getLinesToIgnore () as $ file => $ data ) {
247+ foreach ($ data as $ ignoredFile => $ lines ) {
248+ if ($ ignoredFile !== $ file ) {
249+ continue ;
250+ }
251+
252+ foreach ($ lines as $ line => $ identifiers ) {
253+ if ($ identifiers === null ) {
254+ continue ;
255+ }
256+
257+ foreach ($ identifiers as $ identifier ) {
258+ ['name ' => $ name , 'comment ' => $ comment ] = $ identifier ;
259+ if ($ comment !== null ) {
260+ continue ;
261+ }
262+
263+ $ errors [] = (new Error (
264+ sprintf ('Ignore with identifier %s has no comment. ' , $ name ),
265+ $ file ,
266+ $ line ,
267+ false ,
268+ $ file ,
269+ ))->withIdentifier ('ignore.noComment ' );
270+ }
271+ }
272+ }
273+ }
274+
275+ return new AnalyserResult (
276+ $ errors ,
277+ $ analyserResult ->getFilteredPhpErrors (),
278+ $ analyserResult ->getAllPhpErrors (),
279+ $ analyserResult ->getLocallyIgnoredErrors (),
280+ $ analyserResult ->getLinesToIgnore (),
281+ $ analyserResult ->getUnmatchedLineIgnores (),
282+ $ analyserResult ->getInternalErrors (),
283+ $ analyserResult ->getCollectedData (),
284+ $ analyserResult ->getDependencies (),
285+ $ analyserResult ->getUsedTraitDependencies (),
286+ $ analyserResult ->getExportedNodes (),
287+ $ analyserResult ->hasReachedInternalErrorsCountLimit (),
288+ $ analyserResult ->getPeakMemoryUsageBytes (),
289+ );
290+ }
291+
240292}
0 commit comments