@@ -95,7 +95,7 @@ function processStubFile(string $stubFile, Context $context, bool $includeOnly =
95
95
if (!$ fileInfo = $ context ->parsedFiles [$ stubFile ] ?? null ) {
96
96
initPhpParser ();
97
97
$ stubContent = $ stubCode ?? file_get_contents ($ stubFile );
98
- $ fileInfo = parseStubFile ($ stubContent );
98
+ $ fileInfo = FileInfo:: parseStubFile ($ stubContent );
99
99
$ context ->parsedFiles [$ stubFile ] = $ fileInfo ;
100
100
101
101
foreach ($ fileInfo ->dependencies as $ dependency ) {
@@ -4295,7 +4295,27 @@ public function getLegacyVersion(): FileInfo {
4295
4295
return $ legacyFileInfo ;
4296
4296
}
4297
4297
4298
- public function handleStatements (array $ stmts , PrettyPrinterAbstract $ prettyPrinter ): void {
4298
+ public static function parseStubFile (string $ code ): FileInfo {
4299
+ $ parser = new PhpParser \Parser \Php7 (new PhpParser \Lexer \Emulative ());
4300
+ $ nodeTraverser = new PhpParser \NodeTraverser ;
4301
+ $ nodeTraverser ->addVisitor (new PhpParser \NodeVisitor \NameResolver );
4302
+ $ prettyPrinter = new class extends Standard {
4303
+ protected function pName_FullyQualified (Name \FullyQualified $ node ): string {
4304
+ return implode ('\\' , $ node ->getParts ());
4305
+ }
4306
+ };
4307
+
4308
+ $ stmts = $ parser ->parse ($ code );
4309
+ $ nodeTraverser ->traverse ($ stmts );
4310
+
4311
+ $ fileTags = DocCommentTag::parseDocComments (getFileDocComments ($ stmts ));
4312
+ $ fileInfo = new FileInfo ($ fileTags );
4313
+
4314
+ $ fileInfo ->handleStatements ($ stmts , $ prettyPrinter );
4315
+ return $ fileInfo ;
4316
+ }
4317
+
4318
+ private function handleStatements (array $ stmts , PrettyPrinterAbstract $ prettyPrinter ): void {
4299
4319
$ conds = [];
4300
4320
foreach ($ stmts as $ stmt ) {
4301
4321
$ cond = self ::handlePreprocessorConditions ($ conds , $ stmt );
@@ -5031,26 +5051,6 @@ function getFileDocComments(array $stmts): array {
5031
5051
);
5032
5052
}
5033
5053
5034
- function parseStubFile (string $ code ): FileInfo {
5035
- $ parser = new PhpParser \Parser \Php7 (new PhpParser \Lexer \Emulative ());
5036
- $ nodeTraverser = new PhpParser \NodeTraverser ;
5037
- $ nodeTraverser ->addVisitor (new PhpParser \NodeVisitor \NameResolver );
5038
- $ prettyPrinter = new class extends Standard {
5039
- protected function pName_FullyQualified (Name \FullyQualified $ node ): string {
5040
- return implode ('\\' , $ node ->getParts ());
5041
- }
5042
- };
5043
-
5044
- $ stmts = $ parser ->parse ($ code );
5045
- $ nodeTraverser ->traverse ($ stmts );
5046
-
5047
- $ fileTags = DocCommentTag::parseDocComments (getFileDocComments ($ stmts ));
5048
- $ fileInfo = new FileInfo ($ fileTags );
5049
-
5050
- $ fileInfo ->handleStatements ($ stmts , $ prettyPrinter );
5051
- return $ fileInfo ;
5052
- }
5053
-
5054
5054
/**
5055
5055
* @template T
5056
5056
* @param iterable<T> $infos
0 commit comments