@@ -18,6 +18,7 @@ public function __construct(
18
18
private RuleRegistry $ ruleRegistry ,
19
19
private RuleErrorTransformer $ ruleErrorTransformer ,
20
20
private ScopeFactory $ scopeFactory ,
21
+ private LocalIgnoresProcessor $ localIgnoresProcessor ,
21
22
private bool $ reportUnmatchedIgnoredErrors ,
22
23
)
23
24
{
@@ -39,31 +40,54 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles): Analy
39
40
40
41
$ file = 'N/A ' ;
41
42
$ scope = $ this ->scopeFactory ->create (ScopeContext::create ($ file ));
42
- $ errors = $ analyserResult -> getUnorderedErrors () ;
43
+ $ collectorErrors = [] ;
43
44
foreach ($ this ->ruleRegistry ->getRules ($ nodeType ) as $ rule ) {
44
45
try {
45
46
$ ruleErrors = $ rule ->processNode ($ node , $ scope );
46
47
} 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 ' );
48
49
continue ;
49
50
} 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 ' );
51
52
continue ;
52
53
} 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 ' );
54
55
continue ;
55
56
}
56
57
57
58
foreach ($ ruleErrors as $ ruleError ) {
58
- $ errors [] = $ this ->ruleErrorTransformer ->transform ($ ruleError , $ scope , $ nodeType , $ node ->getStartLine ());
59
+ $ collectorErrors [] = $ this ->ruleErrorTransformer ->transform ($ ruleError , $ scope , $ nodeType , $ node ->getStartLine ());
59
60
}
60
61
}
61
62
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
+
62
86
return $ this ->addUnmatchedIgnoredErrors (new AnalyserResult (
63
87
$ errors ,
64
- $ analyserResult -> getLocallyIgnoredErrors () ,
65
- $ analyserResult -> getLinesToIgnore () ,
66
- $ analyserResult -> getUnmatchedLineIgnores () ,
88
+ $ locallyIgnoredErrors ,
89
+ $ allLinesToIgnore ,
90
+ $ allUnmatchedLineIgnores ,
67
91
$ analyserResult ->getInternalErrors (),
68
92
$ analyserResult ->getCollectedData (),
69
93
$ analyserResult ->getDependencies (),
0 commit comments