2
2
3
3
namespace PHPStan \PhpDoc ;
4
4
5
+ use PHPStan \Analyser \Error ;
5
6
use PHPStan \Analyser \FileAnalyser ;
6
7
use PHPStan \Analyser \NodeScopeResolver ;
7
8
use PHPStan \Broker \Broker ;
@@ -60,7 +61,7 @@ public function __construct(
60
61
* @param string[] $stubFiles
61
62
* @return \PHPStan\Analyser\Error[]
62
63
*/
63
- public function validate (array $ stubFiles ): array
64
+ public function validate (array $ stubFiles, bool $ debug ): array
64
65
{
65
66
if (count ($ stubFiles ) === 0 ) {
66
67
return [];
@@ -84,15 +85,24 @@ public function validate(array $stubFiles): array
84
85
85
86
$ errors = [];
86
87
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 ();
92
98
}
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 );
96
106
}
97
107
}
98
108
0 commit comments