@@ -40,29 +40,30 @@ public function __construct(RectorParser $rectorParser, NodeScopeAndMetadataDeco
4040 }
4141 public function parseFilePathToFile (string $ filePath ): File
4242 {
43- // needed for PHPStan reflection, as it caches the last processed file
44- $ this ->dynamicSourceLocatorProvider ->setFilePath ($ filePath );
45- $ fileContent = FileSystem::read ($ filePath );
46- $ file = new File ($ filePath , $ fileContent );
47- $ stmts = $ this ->rectorParser ->parseString ($ fileContent );
48- $ stmts = $ this ->nodeScopeAndMetadataDecorator ->decorateNodesFromFile ($ filePath , $ stmts );
49- $ file ->hydrateStmtsAndTokens ($ stmts , $ stmts , []);
50- $ this ->currentFileProvider ->setFile ($ file );
43+ [$ file , $ stmts ] = $ this ->parseToFileAndStmts ($ filePath );
5144 return $ file ;
5245 }
5346 /**
5447 * @return Node[]
5548 */
5649 public function parseFileToDecoratedNodes (string $ filePath ): array
50+ {
51+ [$ file , $ stmts ] = $ this ->parseToFileAndStmts ($ filePath );
52+ return $ stmts ;
53+ }
54+ /**
55+ * @return array{0: File, 1: Node[]}
56+ */
57+ private function parseToFileAndStmts (string $ filePath ): array
5758 {
5859 // needed for PHPStan reflection, as it caches the last processed file
5960 $ this ->dynamicSourceLocatorProvider ->setFilePath ($ filePath );
6061 $ fileContent = FileSystem::read ($ filePath );
61- $ stmts = $ this ->rectorParser ->parseString ($ fileContent );
6262 $ file = new File ($ filePath , $ fileContent );
63+ $ stmts = $ this ->rectorParser ->parseString ($ fileContent );
6364 $ stmts = $ this ->nodeScopeAndMetadataDecorator ->decorateNodesFromFile ($ filePath , $ stmts );
6465 $ file ->hydrateStmtsAndTokens ($ stmts , $ stmts , []);
6566 $ this ->currentFileProvider ->setFile ($ file );
66- return $ stmts ;
67+ return [ $ file , $ stmts] ;
6768 }
6869}
0 commit comments