@@ -95,7 +95,7 @@ function processStubFile(string $stubFile, Context $context, bool $includeOnly =
9595 if (!$ fileInfo = $ context ->parsedFiles [$ stubFile ] ?? null ) {
9696 initPhpParser ();
9797 $ stubContent = $ stubCode ?? file_get_contents ($ stubFile );
98- $ fileInfo = parseStubFile ($ stubContent );
98+ $ fileInfo = FileInfo:: parseStubFile ($ stubContent );
9999 $ context ->parsedFiles [$ stubFile ] = $ fileInfo ;
100100
101101 foreach ($ fileInfo ->dependencies as $ dependency ) {
@@ -4268,7 +4268,27 @@ public function getLegacyVersion(): FileInfo {
42684268 return $ legacyFileInfo ;
42694269 }
42704270
4271- public function handleStatements (array $ stmts , PrettyPrinterAbstract $ prettyPrinter ) {
4271+ public static function parseStubFile (string $ code ): FileInfo {
4272+ $ parser = new PhpParser \Parser \Php7 (new PhpParser \Lexer \Emulative ());
4273+ $ nodeTraverser = new PhpParser \NodeTraverser ;
4274+ $ nodeTraverser ->addVisitor (new PhpParser \NodeVisitor \NameResolver );
4275+ $ prettyPrinter = new class extends Standard {
4276+ protected function pName_FullyQualified (Name \FullyQualified $ node ): string {
4277+ return implode ('\\' , $ node ->getParts ());
4278+ }
4279+ };
4280+
4281+ $ stmts = $ parser ->parse ($ code );
4282+ $ nodeTraverser ->traverse ($ stmts );
4283+
4284+ $ fileTags = DocCommentTag::parseDocComments (getFileDocComments ($ stmts ));
4285+ $ fileInfo = new FileInfo ($ fileTags );
4286+
4287+ $ fileInfo ->handleStatements ($ stmts , $ prettyPrinter );
4288+ return $ fileInfo ;
4289+ }
4290+
4291+ private function handleStatements (array $ stmts , PrettyPrinterAbstract $ prettyPrinter ) {
42724292 $ conds = [];
42734293 foreach ($ stmts as $ stmt ) {
42744294 $ cond = self ::handlePreprocessorConditions ($ conds , $ stmt );
@@ -5004,26 +5024,6 @@ function getFileDocComments(array $stmts): array {
50045024 );
50055025}
50065026
5007- function parseStubFile (string $ code ): FileInfo {
5008- $ parser = new PhpParser \Parser \Php7 (new PhpParser \Lexer \Emulative ());
5009- $ nodeTraverser = new PhpParser \NodeTraverser ;
5010- $ nodeTraverser ->addVisitor (new PhpParser \NodeVisitor \NameResolver );
5011- $ prettyPrinter = new class extends Standard {
5012- protected function pName_FullyQualified (Name \FullyQualified $ node ): string {
5013- return implode ('\\' , $ node ->getParts ());
5014- }
5015- };
5016-
5017- $ stmts = $ parser ->parse ($ code );
5018- $ nodeTraverser ->traverse ($ stmts );
5019-
5020- $ fileTags = DocCommentTag::parseDocComments (getFileDocComments ($ stmts ));
5021- $ fileInfo = new FileInfo ($ fileTags );
5022-
5023- $ fileInfo ->handleStatements ($ stmts , $ prettyPrinter );
5024- return $ fileInfo ;
5025- }
5026-
50275027/**
50285028 * @template T
50295029 * @param iterable<T> $infos
0 commit comments