@@ -385,7 +385,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
385385 }
386386
387387 $ internalErrorsTuples = array_values ($ internalErrorsTuples );
388- $ bugReportUrl = 'https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml ' ;
389388
390389 /**
391390 * Variable $internalErrors only contains non-file-specific "internal errors".
@@ -396,32 +395,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
396395 continue ;
397396 }
398397
399- $ message = sprintf ('%s while %s ' , $ internalError ->getMessage (), $ internalError ->getContextDescription ());
400- if ($ internalError ->getTraceAsString () !== null ) {
401- if (OutputInterface::VERBOSITY_VERBOSE <= $ output ->getVerbosity ()) {
402- $ firstTraceItem = $ internalError ->getTrace ()[0 ] ?? null ;
403- $ trace = '' ;
404- if ($ firstTraceItem !== null && $ firstTraceItem ['file ' ] !== null && $ firstTraceItem ['line ' ] !== null ) {
405- $ trace = sprintf ('## %s(%d)%s ' , $ firstTraceItem ['file ' ], $ firstTraceItem ['line ' ], "\n" );
406- }
407- $ trace .= $ internalError ->getTraceAsString ();
408-
409- if ($ internalError ->shouldReportBug ()) {
410- $ message .= sprintf ('%sPost the following stack trace to %s: %s%s ' , "\n" , $ bugReportUrl , "\n" , $ trace );
411- } else {
412- $ message .= sprintf ('%s%s ' , "\n\n" , $ trace );
413- }
414- } else {
415- if ($ internalError ->shouldReportBug ()) {
416- $ message .= sprintf ('%sRun PHPStan with -v option and post the stack trace to:%s%s%s ' , "\n\n" , "\n" , $ bugReportUrl , "\n" );
417- } else {
418- $ message .= sprintf ('%sRun PHPStan with -v option to see the stack trace ' , "\n" );
419- }
420- }
421- }
422-
423398 $ internalErrors [] = new InternalError (
424- $ message ,
399+ $ this -> getMessageFromInternalError ( $ internalError , $ output -> getVerbosity ()) ,
425400 $ internalError ->getContextDescription (),
426401 $ internalError ->getTrace (),
427402 $ internalError ->getTraceAsString (),
@@ -555,6 +530,36 @@ private function createStreamOutput(): StreamOutput
555530 return new StreamOutput ($ resource );
556531 }
557532
533+ private function getMessageFromInternalError (InternalError $ internalError , int $ verbosity ): string
534+ {
535+ $ bugReportUrl = 'https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml ' ;
536+ $ message = sprintf ('%s while %s ' , $ internalError ->getMessage (), $ internalError ->getContextDescription ());
537+ if ($ internalError ->getTraceAsString () !== null ) {
538+ if (OutputInterface::VERBOSITY_VERBOSE <= $ verbosity ) {
539+ $ firstTraceItem = $ internalError ->getTrace ()[0 ] ?? null ;
540+ $ trace = '' ;
541+ if ($ firstTraceItem !== null && $ firstTraceItem ['file ' ] !== null && $ firstTraceItem ['line ' ] !== null ) {
542+ $ trace = sprintf ('## %s(%d)%s ' , $ firstTraceItem ['file ' ], $ firstTraceItem ['line ' ], "\n" );
543+ }
544+ $ trace .= $ internalError ->getTraceAsString ();
545+
546+ if ($ internalError ->shouldReportBug ()) {
547+ $ message .= sprintf ('%sPost the following stack trace to %s: %s%s ' , "\n" , $ bugReportUrl , "\n" , $ trace );
548+ } else {
549+ $ message .= sprintf ('%s%s ' , "\n\n" , $ trace );
550+ }
551+ } else {
552+ if ($ internalError ->shouldReportBug ()) {
553+ $ message .= sprintf ('%sRun PHPStan with -v option and post the stack trace to:%s%s%s ' , "\n\n" , "\n" , $ bugReportUrl , "\n" );
554+ } else {
555+ $ message .= sprintf ('%sRun PHPStan with -v option to see the stack trace ' , "\n" );
556+ }
557+ }
558+ }
559+
560+ return $ message ;
561+ }
562+
558563 private function generateBaseline (string $ generateBaselineFile , InceptionResult $ inceptionResult , AnalysisResult $ analysisResult , OutputInterface $ output , bool $ allowEmptyBaseline , string $ baselineExtension , bool $ failWithoutResultCache ): int
559564 {
560565 if (!$ allowEmptyBaseline && !$ analysisResult ->hasErrors ()) {
0 commit comments