@@ -210,6 +210,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
210210 $ configuration ,
211211 $ input ,
212212 function (array $ errors , array $ locallyIgnoredErrors , array $ analysedFiles ) use ($ out , $ ignoredErrorHelperResult , $ isOnlyFiles , $ inceptionFiles ): void {
213+ $ internalErrors = [];
214+ foreach ($ errors as $ fileSpecificError ) {
215+ if (!$ fileSpecificError ->hasNonIgnorableException ()) {
216+ continue ;
217+ }
218+
219+ $ internalErrors [] = $ this ->transformErrorIntoInternalError ($ fileSpecificError );
220+ }
221+
222+ if (count ($ internalErrors ) > 0 ) {
223+ $ out ->write (['action ' => 'analysisCrash ' , 'data ' => [
224+ 'internalErrors ' => $ internalErrors ,
225+ ]]);
226+ return ;
227+ }
228+
213229 [$ errors , $ ignoredErrors ] = $ this ->filterErrors ($ errors , $ ignoredErrorHelperResult , $ isOnlyFiles , $ inceptionFiles , false );
214230 foreach ($ locallyIgnoredErrors as $ locallyIgnoredError ) {
215231 $ ignoredErrors [] = [$ locallyIgnoredError , null ];
@@ -249,22 +265,7 @@ function (array $errors, array $locallyIgnoredErrors, array $analysedFiles) use
249265 continue ;
250266 }
251267
252- $ message = $ fileSpecificError ->getMessage ();
253- $ metadata = $ fileSpecificError ->getMetadata ();
254- if (
255- $ fileSpecificError ->getIdentifier () === 'phpstan.internal '
256- && array_key_exists (InternalError::STACK_TRACE_AS_STRING_METADATA_KEY , $ metadata )
257- ) {
258- $ message = sprintf ('Internal error: %s ' , $ message );
259- }
260-
261- $ internalErrors [] = new InternalError (
262- $ message ,
263- sprintf ('analysing file %s ' , $ fileSpecificError ->getTraitFilePath () ?? $ fileSpecificError ->getFilePath ()),
264- $ metadata [InternalError::STACK_TRACE_METADATA_KEY ] ?? [],
265- $ metadata [InternalError::STACK_TRACE_AS_STRING_METADATA_KEY ] ?? null ,
266- true ,
267- );
268+ $ internalErrors [] = $ this ->transformErrorIntoInternalError ($ fileSpecificError );
268269 }
269270
270271 $ hasInternalErrors = count ($ internalErrors ) > 0 || $ finalizerResult ->getAnalyserResult ()->hasReachedInternalErrorsCountLimit ();
@@ -327,6 +328,26 @@ function (array $errors, array $locallyIgnoredErrors, array $analysedFiles) use
327328 return 0 ;
328329 }
329330
331+ private function transformErrorIntoInternalError (Error $ error ): InternalError
332+ {
333+ $ message = $ error ->getMessage ();
334+ $ metadata = $ error ->getMetadata ();
335+ if (
336+ $ error ->getIdentifier () === 'phpstan.internal '
337+ && array_key_exists (InternalError::STACK_TRACE_AS_STRING_METADATA_KEY , $ metadata )
338+ ) {
339+ $ message = sprintf ('Internal error: %s ' , $ message );
340+ }
341+
342+ return new InternalError (
343+ $ message ,
344+ sprintf ('analysing file %s ' , $ error ->getTraitFilePath () ?? $ error ->getFilePath ()),
345+ $ metadata [InternalError::STACK_TRACE_METADATA_KEY ] ?? [],
346+ $ metadata [InternalError::STACK_TRACE_AS_STRING_METADATA_KEY ] ?? null ,
347+ true ,
348+ );
349+ }
350+
330351 /**
331352 * @param string[] $inceptionFiles
332353 * @param array<Error> $errors
0 commit comments