22
33namespace PHPStan \PhpDoc ;
44
5+ use PHPStan \Analyser \Error ;
56use PHPStan \Analyser \FileAnalyser ;
67use PHPStan \Analyser \NodeScopeResolver ;
78use PHPStan \Broker \Broker ;
@@ -60,7 +61,7 @@ public function __construct(
6061 * @param string[] $stubFiles
6162 * @return \PHPStan\Analyser\Error[]
6263 */
63- public function validate (array $ stubFiles ): array
64+ public function validate (array $ stubFiles, bool $ debug ): array
6465 {
6566 if (count ($ stubFiles ) === 0 ) {
6667 return [];
@@ -84,15 +85,24 @@ public function validate(array $stubFiles): array
8485
8586 $ errors = [];
8687 foreach ($ stubFiles as $ stubFile ) {
87- $ tmpErrors = $ fileAnalyser ->analyseFile (
88- $ stubFile ,
89- $ analysedFiles ,
90- $ ruleRegistry ,
91- static function (): void {
88+ try {
89+ $ tmpErrors = $ fileAnalyser ->analyseFile (
90+ $ stubFile ,
91+ $ analysedFiles ,
92+ $ ruleRegistry ,
93+ static function (): void {
94+ }
95+ )->getErrors ();
96+ foreach ($ tmpErrors as $ tmpError ) {
97+ $ errors [] = $ tmpError ->withoutTip ();
9298 }
93- )->getErrors ();
94- foreach ($ tmpErrors as $ tmpError ) {
95- $ errors [] = $ tmpError ->withoutTip ();
99+ } catch (\Throwable $ e ) {
100+ if ($ debug ) {
101+ throw $ e ;
102+ }
103+
104+ $ internalErrorMessage = sprintf ('Internal error: %s ' , $ e ->getMessage ());
105+ $ errors [] = new Error ($ internalErrorMessage , $ stubFile , null , $ e );
96106 }
97107 }
98108
0 commit comments