@@ -131,13 +131,14 @@ public function analyse(
131
131
$ internalErrorsCount = 0 ;
132
132
$ reachedInternalErrorsCountLimit = false ;
133
133
foreach ($ files as $ file ) {
134
- try {
135
- $ fileErrors = [] ;
136
- if ( $ preFileCallback !== null ) {
137
- $ preFileCallback ( $ file );
138
- }
134
+ if ( $ preFileCallback !== null ) {
135
+ $ preFileCallback ( $ file ) ;
136
+ }
137
+
138
+ $ fileErrors = [];
139
139
140
- if (is_file ($ file )) {
140
+ if (is_file ($ file )) {
141
+ try {
141
142
$ parserNodes = $ this ->parser ->parseFile ($ file );
142
143
$ nodeCallback = function (\PhpParser \Node $ node , Scope $ scope ) use (&$ fileErrors , $ file , $ outerNodeCallback ): void {
143
144
if ($ outerNodeCallback !== null ) {
@@ -212,42 +213,42 @@ public function analyse(
212
213
$ scope ,
213
214
$ nodeCallback
214
215
);
215
- } elseif (is_dir ($ file )) {
216
- $ fileErrors [] = new Error (sprintf ('File %s is a directory. ' , $ file ), $ file , null , false );
217
- } else {
218
- $ fileErrors [] = new Error (sprintf ('File %s does not exist. ' , $ file ), $ file , null , false );
219
- }
220
- if ($ postFileCallback !== null ) {
221
- $ postFileCallback ($ file );
222
- }
223
-
224
- $ errors = array_merge ($ errors , $ fileErrors );
225
- } catch (\PhpParser \Error $ e ) {
226
- $ errors [] = new Error ($ e ->getMessage (), $ file , $ e ->getStartLine () !== -1 ? $ e ->getStartLine () : null , false );
227
- } catch (\PHPStan \Parser \ParserErrorsException $ e ) {
228
- foreach ($ e ->getErrors () as $ error ) {
229
- $ errors [] = new Error ($ error ->getMessage (), $ file , $ error ->getStartLine () !== -1 ? $ error ->getStartLine () : null , false );
230
- }
231
- } catch (\PHPStan \AnalysedCodeException $ e ) {
232
- $ errors [] = new Error ($ e ->getMessage (), $ file , null , false );
233
- } catch (\Throwable $ t ) {
234
- if ($ debug ) {
235
- throw $ t ;
236
- }
237
- $ internalErrorsCount ++;
238
- $ internalErrorMessage = sprintf ('Internal error: %s ' , $ t ->getMessage ());
239
- $ internalErrorMessage .= sprintf (
240
- '%sRun PHPStan with --debug option and post the stack trace to:%s%s ' ,
241
- "\n" ,
242
- "\n" ,
243
- 'https://github.com/phpstan/phpstan/issues/new '
244
- );
245
- $ errors [] = new Error ($ internalErrorMessage , $ file );
246
- if ($ internalErrorsCount >= $ this ->internalErrorsCountLimit ) {
247
- $ reachedInternalErrorsCountLimit = true ;
248
- break ;
216
+ } catch (\PhpParser \Error $ e ) {
217
+ $ errors [] = new Error ($ e ->getMessage (), $ file , $ e ->getStartLine () !== -1 ? $ e ->getStartLine () : null , false );
218
+ } catch (\PHPStan \Parser \ParserErrorsException $ e ) {
219
+ foreach ($ e ->getErrors () as $ error ) {
220
+ $ errors [] = new Error ($ error ->getMessage (), $ file , $ error ->getStartLine () !== -1 ? $ error ->getStartLine () : null , false );
221
+ }
222
+ } catch (\PHPStan \AnalysedCodeException $ e ) {
223
+ $ errors [] = new Error ($ e ->getMessage (), $ file , null , false );
224
+ } catch (\Throwable $ t ) {
225
+ if ($ debug ) {
226
+ throw $ t ;
227
+ }
228
+ $ internalErrorsCount ++;
229
+ $ internalErrorMessage = sprintf ('Internal error: %s ' , $ t ->getMessage ());
230
+ $ internalErrorMessage .= sprintf (
231
+ '%sRun PHPStan with --debug option and post the stack trace to:%s%s ' ,
232
+ "\n" ,
233
+ "\n" ,
234
+ 'https://github.com/phpstan/phpstan/issues/new '
235
+ );
236
+ $ errors [] = new Error ($ internalErrorMessage , $ file );
237
+ if ($ internalErrorsCount >= $ this ->internalErrorsCountLimit ) {
238
+ $ reachedInternalErrorsCountLimit = true ;
239
+ break ;
240
+ }
249
241
}
242
+ } elseif (is_dir ($ file )) {
243
+ $ fileErrors [] = new Error (sprintf ('File %s is a directory. ' , $ file ), $ file , null , false );
244
+ } else {
245
+ $ fileErrors [] = new Error (sprintf ('File %s does not exist. ' , $ file ), $ file , null , false );
250
246
}
247
+ if ($ postFileCallback !== null ) {
248
+ $ postFileCallback ($ file );
249
+ }
250
+
251
+ $ errors = array_merge ($ errors , $ fileErrors );
251
252
}
252
253
253
254
$ this ->restoreCollectErrorsHandler ();
0 commit comments