33namespace PHPStan \Command ;
44
55use PHPStan \Analyser \Analyser ;
6+ use PHPStan \Analyser \AnalyserResult ;
67use PHPStan \Command \ErrorFormatter \ErrorFormatter ;
78use PHPStan \Parallel \ParallelAnalyser ;
89use PHPStan \Parallel \Scheduler ;
@@ -72,7 +73,7 @@ public function analyse(
7273 ): int
7374 {
7475 $ this ->updateMemoryLimitFile ();
75- $ errors = $ this ->stubValidator ->validate ();
76+ $ stubErrors = $ this ->stubValidator ->validate ();
7677
7778 register_shutdown_function (function (): void {
7879 $ error = error_get_last ();
@@ -90,6 +91,59 @@ public function analyse(
9091 @unlink ($ this ->memoryLimitFile );
9192 });
9293
94+ $ analyserResult = $ this ->runAnalyser (
95+ $ files ,
96+ $ onlyFiles ,
97+ $ debug ,
98+ $ projectConfigFile ,
99+ $ stdOutput ,
100+ $ errorOutput ,
101+ $ input
102+ );
103+
104+ $ errors = array_merge ($ stubErrors , $ analyserResult ->getErrors ());
105+
106+ $ fileSpecificErrors = [];
107+ $ notFileSpecificErrors = [];
108+ $ warnings = [];
109+ foreach ($ errors as $ error ) {
110+ if (is_string ($ error )) {
111+ $ notFileSpecificErrors [] = $ error ;
112+ } else {
113+ if ($ error ->isWarning ()) {
114+ $ warnings [] = $ error ->getMessage ();
115+ continue ;
116+ }
117+ $ fileSpecificErrors [] = $ error ;
118+ }
119+ }
120+
121+ return $ errorFormatter ->formatErrors (
122+ new AnalysisResult (
123+ $ fileSpecificErrors ,
124+ $ notFileSpecificErrors ,
125+ $ warnings ,
126+ $ defaultLevelUsed ,
127+ $ analyserResult ->hasInferrablePropertyTypesFromConstructor (),
128+ $ projectConfigFile
129+ ),
130+ $ stdOutput
131+ );
132+ }
133+
134+ /**
135+ * @param string[] $files
136+ */
137+ private function runAnalyser (
138+ array $ files ,
139+ bool $ onlyFiles ,
140+ bool $ debug ,
141+ ?string $ projectConfigFile ,
142+ Output $ stdOutput ,
143+ Output $ errorOutput ,
144+ InputInterface $ input
145+ ): AnalyserResult
146+ {
93147 /** @var bool $runningInParallel */
94148 $ runningInParallel = false ;
95149
@@ -135,9 +189,7 @@ public function analyse(
135189 && $ schedule ->getNumberOfProcesses () > 1
136190 ) {
137191 $ runningInParallel = true ;
138- $ parallelAnalyserResult = $ this ->parallelAnalyser ->analyse ($ schedule , $ mainScript , $ onlyFiles , $ postFileCallback , $ projectConfigFile , $ input );
139- $ errors = array_merge ($ errors , $ parallelAnalyserResult ->getErrors ());
140- $ hasInferrablePropertyTypesFromConstructor = $ parallelAnalyserResult ->hasInferrablePropertyTypesFromConstructor ();
192+ $ analyserResult = $ this ->parallelAnalyser ->analyse ($ schedule , $ mainScript , $ onlyFiles , $ postFileCallback , $ projectConfigFile , $ input );
141193 } else {
142194 $ analyserResult = $ this ->analyser ->analyse (
143195 $ files ,
@@ -146,40 +198,13 @@ public function analyse(
146198 $ postFileCallback ,
147199 $ debug
148200 );
149- $ errors = array_merge ($ errors , $ analyserResult ->getErrors ());
150- $ hasInferrablePropertyTypesFromConstructor = $ analyserResult ->hasInferrablePropertyTypesFromConstructor ();
151201 }
152202
153203 if (isset ($ progressStarted ) && $ progressStarted ) {
154204 $ errorOutput ->getStyle ()->progressFinish ();
155205 }
156206
157- $ fileSpecificErrors = [];
158- $ notFileSpecificErrors = [];
159- $ warnings = [];
160- foreach ($ errors as $ error ) {
161- if (is_string ($ error )) {
162- $ notFileSpecificErrors [] = $ error ;
163- } else {
164- if ($ error ->isWarning ()) {
165- $ warnings [] = $ error ->getMessage ();
166- continue ;
167- }
168- $ fileSpecificErrors [] = $ error ;
169- }
170- }
171-
172- return $ errorFormatter ->formatErrors (
173- new AnalysisResult (
174- $ fileSpecificErrors ,
175- $ notFileSpecificErrors ,
176- $ warnings ,
177- $ defaultLevelUsed ,
178- $ hasInferrablePropertyTypesFromConstructor ,
179- $ projectConfigFile
180- ),
181- $ stdOutput
182- );
207+ return $ analyserResult ;
183208 }
184209
185210 private function updateMemoryLimitFile (): void
0 commit comments