@@ -28,18 +28,19 @@ public function __construct(
2828 private LocalIgnoresProcessor $ localIgnoresProcessor ,
2929 #[AutowiredParameter]
3030 private bool $ reportUnmatchedIgnoredErrors ,
31- #[AutowiredParameter]
32- private bool $ reportIgnoresWithoutComments ,
3331 )
3432 {
3533 }
3634
3735 public function finalize (AnalyserResult $ analyserResult , bool $ onlyFiles , bool $ debug ): FinalizerResult
3836 {
39- $ hasCollectedData = count ($ analyserResult ->getCollectedData ()) > 0 ;
37+ if (count ($ analyserResult ->getCollectedData ()) === 0 ) {
38+ return $ this ->addUnmatchedIgnoredErrors ($ this ->mergeFilteredPhpErrors ($ analyserResult ), [], []);
39+ }
40+
4041 $ hasInternalErrors = count ($ analyserResult ->getInternalErrors ()) > 0 || $ analyserResult ->hasReachedInternalErrorsCountLimit ();
41- if (! $ hasCollectedData || $ hasInternalErrors ) {
42- return $ this ->addUnmatchedIgnoredErrors ($ this ->addIgnoresWithoutCommentErrors ( $ this -> mergeFilteredPhpErrors ($ analyserResult) ), [], []);
42+ if ($ hasInternalErrors ) {
43+ return $ this ->addUnmatchedIgnoredErrors ($ this ->mergeFilteredPhpErrors ($ analyserResult ), [], []);
4344 }
4445
4546 $ nodeType = CollectedDataNode::class;
@@ -133,7 +134,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
133134 $ allUnmatchedLineIgnores [$ file ] = $ localIgnoresProcessorResult ->getUnmatchedLineIgnores ();
134135 }
135136
136- return $ this ->addUnmatchedIgnoredErrors ($ this -> addIgnoresWithoutCommentErrors ( new AnalyserResult (
137+ return $ this ->addUnmatchedIgnoredErrors (new AnalyserResult (
137138 unorderedErrors: array_merge ($ errors , $ analyserResult ->getFilteredPhpErrors ()),
138139 filteredPhpErrors: [],
139140 allPhpErrors: $ analyserResult ->getAllPhpErrors (),
@@ -147,7 +148,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
147148 exportedNodes: $ analyserResult ->getExportedNodes (),
148149 reachedInternalErrorsCountLimit: $ analyserResult ->hasReachedInternalErrorsCountLimit (),
149150 peakMemoryUsageBytes: $ analyserResult ->getPeakMemoryUsageBytes (),
150- )) , $ collectorErrors , $ locallyIgnoredCollectorErrors );
151+ ), $ collectorErrors , $ locallyIgnoredCollectorErrors );
151152 }
152153
153154 private function mergeFilteredPhpErrors (AnalyserResult $ analyserResult ): AnalyserResult
@@ -204,7 +205,7 @@ private function addUnmatchedIgnoredErrors(
204205
205206 foreach ($ identifiers as $ identifier ) {
206207 $ errors [] = (new Error (
207- sprintf ('No error with identifier %s is reported on line %d. ' , $ identifier[ ' name ' ] , $ line ),
208+ sprintf ('No error with identifier %s is reported on line %d. ' , $ identifier , $ line ),
208209 $ file ,
209210 $ line ,
210211 false ,
@@ -236,59 +237,4 @@ private function addUnmatchedIgnoredErrors(
236237 );
237238 }
238239
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- null ,
270- 'Explain why this ignore is necessary in parentheses after the identifier. ' ,
271- ))->withIdentifier ('ignore.noComment ' );
272- }
273- }
274- }
275- }
276-
277- return new AnalyserResult (
278- $ errors ,
279- $ analyserResult ->getFilteredPhpErrors (),
280- $ analyserResult ->getAllPhpErrors (),
281- $ analyserResult ->getLocallyIgnoredErrors (),
282- $ analyserResult ->getLinesToIgnore (),
283- $ analyserResult ->getUnmatchedLineIgnores (),
284- $ analyserResult ->getInternalErrors (),
285- $ analyserResult ->getCollectedData (),
286- $ analyserResult ->getDependencies (),
287- $ analyserResult ->getUsedTraitDependencies (),
288- $ analyserResult ->getExportedNodes (),
289- $ analyserResult ->hasReachedInternalErrorsCountLimit (),
290- $ analyserResult ->getPeakMemoryUsageBytes (),
291- );
292- }
293-
294240}
0 commit comments