8
8
use Nette \Utils \Random ;
9
9
use PHPStan \Analyser \AnalyserResult ;
10
10
use PHPStan \Analyser \Error ;
11
+ use PHPStan \Analyser \InternalError ;
11
12
use PHPStan \Collectors \CollectedData ;
12
13
use PHPStan \Dependency \RootExportedNode ;
13
14
use PHPStan \Process \ProcessHelper ;
25
26
use function count ;
26
27
use function defined ;
27
28
use function ini_get ;
28
- use function is_string ;
29
29
use function max ;
30
30
use function memory_get_usage ;
31
31
use function parse_url ;
@@ -90,7 +90,7 @@ public function analyse(
90
90
$ server = new TcpServer ('127.0.0.1:0 ' , $ loop );
91
91
$ this ->processPool = new ProcessPool ($ server , static function () use ($ deferred , &$ jobs , &$ internalErrors , &$ internalErrorsCount , &$ reachedInternalErrorsCountLimit , &$ errors , &$ filteredPhpErrors , &$ allPhpErrors , &$ locallyIgnoredErrors , &$ linesToIgnore , &$ unmatchedLineIgnores , &$ collectedData , &$ dependencies , &$ exportedNodes , &$ peakMemoryUsages ): void {
92
92
if (count ($ jobs ) > 0 && $ internalErrorsCount === 0 ) {
93
- $ internalErrors [] = 'Some parallel worker jobs have not finished. ' ;
93
+ $ internalErrors [] = new InternalError ( 'Some parallel worker jobs have not finished. ' ) ;
94
94
$ internalErrorsCount ++;
95
95
}
96
96
@@ -139,7 +139,7 @@ public function analyse(
139
139
$ serverPort = parse_url ($ serverAddress , PHP_URL_PORT );
140
140
141
141
$ handleError = function (Throwable $ error ) use (&$ internalErrors , &$ internalErrorsCount , &$ reachedInternalErrorsCountLimit ): void {
142
- $ internalErrors [] = sprintf ( ' Internal error: ' . $ error ->getMessage ());
142
+ $ internalErrors [] = new InternalError ( $ error ->getMessage ());
143
143
$ internalErrorsCount ++;
144
144
$ reachedInternalErrorsCountLimit = true ;
145
145
$ this ->processPool ->quitAll ();
@@ -168,13 +168,11 @@ public function analyse(
168
168
$ process ->start (function (array $ json ) use ($ process , &$ internalErrors , &$ errors , &$ filteredPhpErrors , &$ allPhpErrors , &$ locallyIgnoredErrors , &$ linesToIgnore , &$ unmatchedLineIgnores , &$ collectedData , &$ dependencies , &$ exportedNodes , &$ peakMemoryUsages , &$ jobs , $ postFileCallback , &$ internalErrorsCount , &$ reachedInternalErrorsCountLimit , $ processIdentifier , $ onFileAnalysisHandler ): void {
169
169
$ fileErrors = [];
170
170
foreach ($ json ['errors ' ] as $ jsonError ) {
171
- if (is_string ($ jsonError )) {
172
- $ internalErrors [] = sprintf ('Internal error: %s ' , $ jsonError );
173
- continue ;
174
- }
175
-
176
171
$ fileErrors [] = Error::decode ($ jsonError );
177
172
}
173
+ foreach ($ json ['internalErrors ' ] as $ internalJsonError ) {
174
+ $ internalErrors [] = InternalError::decode ($ internalJsonError );
175
+ }
178
176
179
177
foreach ($ json ['filteredPhpErrors ' ] as $ filteredPhpError ) {
180
178
$ filteredPhpErrors [] = Error::decode ($ filteredPhpError );
@@ -280,13 +278,13 @@ public function analyse(
280
278
$ memoryLimitMessage = 'PHPStan process crashed because it reached configured PHP memory limit ' ;
281
279
if (str_contains ($ output , $ memoryLimitMessage )) {
282
280
foreach ($ internalErrors as $ internalError ) {
283
- if (!str_contains ($ internalError , $ memoryLimitMessage )) {
281
+ if (!str_contains ($ internalError-> getMessage () , $ memoryLimitMessage )) {
284
282
continue ;
285
283
}
286
284
287
285
return ;
288
286
}
289
- $ internalErrors [] = sprintf (sprintf (
287
+ $ internalErrors [] = new InternalError (sprintf (
290
288
"<error>Child process error</error>: %s: %s \n%s \n" ,
291
289
$ memoryLimitMessage ,
292
290
ini_get ('memory_limit ' ),
@@ -296,7 +294,7 @@ public function analyse(
296
294
return ;
297
295
}
298
296
299
- $ internalErrors [] = sprintf ('<error>Child process error</error> (exit code %d): %s ' , $ exitCode , $ output );
297
+ $ internalErrors [] = new InternalError ( sprintf ('<error>Child process error</error> (exit code %d): %s ' , $ exitCode , $ output) );
300
298
$ internalErrorsCount ++;
301
299
});
302
300
$ this ->processPool ->attachProcess ($ processIdentifier , $ process );
0 commit comments