@@ -18,6 +18,7 @@ public function __construct(
1818 private RuleRegistry $ ruleRegistry ,
1919 private RuleErrorTransformer $ ruleErrorTransformer ,
2020 private ScopeFactory $ scopeFactory ,
21+ private LocalIgnoresProcessor $ localIgnoresProcessor ,
2122 private bool $ reportUnmatchedIgnoredErrors ,
2223 )
2324 {
@@ -39,31 +40,54 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles): Analy
3940
4041 $ file = 'N/A ' ;
4142 $ scope = $ this ->scopeFactory ->create (ScopeContext::create ($ file ));
42- $ errors = $ analyserResult -> getUnorderedErrors () ;
43+ $ collectorErrors = [] ;
4344 foreach ($ this ->ruleRegistry ->getRules ($ nodeType ) as $ rule ) {
4445 try {
4546 $ ruleErrors = $ rule ->processNode ($ node , $ scope );
4647 } catch (AnalysedCodeException $ e ) {
47- $ errors [] = (new Error ($ e ->getMessage (), $ file , $ node ->getStartLine (), $ e , null , null , $ e ->getTip ()))->withIdentifier ('phpstan.internal ' );
48+ $ collectorErrors [] = (new Error ($ e ->getMessage (), $ file , $ node ->getStartLine (), $ e , null , null , $ e ->getTip ()))->withIdentifier ('phpstan.internal ' );
4849 continue ;
4950 } catch (IdentifierNotFound $ e ) {
50- $ errors [] = (new Error (sprintf ('Reflection error: %s not found. ' , $ e ->getIdentifier ()->getName ()), $ file , $ node ->getStartLine (), $ e , null , null , 'Learn more at https://phpstan.org/user-guide/discovering-symbols ' ))->withIdentifier ('phpstan.reflection ' );
51+ $ collectorErrors [] = (new Error (sprintf ('Reflection error: %s not found. ' , $ e ->getIdentifier ()->getName ()), $ file , $ node ->getStartLine (), $ e , null , null , 'Learn more at https://phpstan.org/user-guide/discovering-symbols ' ))->withIdentifier ('phpstan.reflection ' );
5152 continue ;
5253 } catch (UnableToCompileNode | CircularReference $ e ) {
53- $ errors [] = (new Error (sprintf ('Reflection error: %s ' , $ e ->getMessage ()), $ file , $ node ->getStartLine (), $ e ))->withIdentifier ('phpstan.reflection ' );
54+ $ collectorErrors [] = (new Error (sprintf ('Reflection error: %s ' , $ e ->getMessage ()), $ file , $ node ->getStartLine (), $ e ))->withIdentifier ('phpstan.reflection ' );
5455 continue ;
5556 }
5657
5758 foreach ($ ruleErrors as $ ruleError ) {
58- $ errors [] = $ this ->ruleErrorTransformer ->transform ($ ruleError , $ scope , $ nodeType , $ node ->getStartLine ());
59+ $ collectorErrors [] = $ this ->ruleErrorTransformer ->transform ($ ruleError , $ scope , $ nodeType , $ node ->getStartLine ());
5960 }
6061 }
6162
63+ $ errors = $ analyserResult ->getUnorderedErrors ();
64+ $ locallyIgnoredErrors = $ analyserResult ->getLocallyIgnoredErrors ();
65+ $ allLinesToIgnore = $ analyserResult ->getLinesToIgnore ();
66+ $ allUnmatchedLineIgnores = $ analyserResult ->getUnmatchedLineIgnores ();
67+ foreach ($ collectorErrors as $ collectorError ) {
68+ $ file = $ collectorError ->getFilePath ();
69+ $ linesToIgnore = $ allLinesToIgnore [$ file ] ?? [];
70+ $ unmatchedLineIgnores = $ allUnmatchedLineIgnores [$ file ] ?? [];
71+ $ localIgnoresProcessorResult = $ this ->localIgnoresProcessor ->process (
72+ [$ collectorError ],
73+ $ linesToIgnore ,
74+ $ unmatchedLineIgnores ,
75+ );
76+ foreach ($ localIgnoresProcessorResult ->getFileErrors () as $ error ) {
77+ $ errors [] = $ error ;
78+ }
79+ foreach ($ localIgnoresProcessorResult ->getLocallyIgnoredErrors () as $ locallyIgnoredError ) {
80+ $ locallyIgnoredErrors [] = $ locallyIgnoredError ;
81+ }
82+ $ allLinesToIgnore [$ file ] = $ localIgnoresProcessorResult ->getLinesToIgnore ();
83+ $ allUnmatchedLineIgnores [$ file ] = $ localIgnoresProcessorResult ->getUnmatchedLineIgnores ();
84+ }
85+
6286 return $ this ->addUnmatchedIgnoredErrors (new AnalyserResult (
6387 $ errors ,
64- $ analyserResult -> getLocallyIgnoredErrors () ,
65- $ analyserResult -> getLinesToIgnore () ,
66- $ analyserResult -> getUnmatchedLineIgnores () ,
88+ $ locallyIgnoredErrors ,
89+ $ allLinesToIgnore ,
90+ $ allUnmatchedLineIgnores ,
6791 $ analyserResult ->getInternalErrors (),
6892 $ analyserResult ->getCollectedData (),
6993 $ analyserResult ->getDependencies (),
0 commit comments