@@ -27,17 +27,7 @@ public function __construct(
2727
2828 public function parseFilePathToFile (string $ filePath ): File
2929 {
30- // needed for PHPStan reflection, as it caches the last processed file
31- $ this ->dynamicSourceLocatorProvider ->setFilePath ($ filePath );
32-
33- $ fileContent = FileSystem::read ($ filePath );
34- $ file = new File ($ filePath , $ fileContent );
35- $ stmts = $ this ->rectorParser ->parseString ($ fileContent );
36-
37- $ stmts = $ this ->nodeScopeAndMetadataDecorator ->decorateNodesFromFile ($ filePath , $ stmts );
38-
39- $ file ->hydrateStmtsAndTokens ($ stmts , $ stmts , []);
40- $ this ->currentFileProvider ->setFile ($ file );
30+ [$ file , $ stmts ] = $ this ->parseToFileAndStmts ($ filePath );
4131
4232 return $ file ;
4333 }
@@ -46,19 +36,29 @@ public function parseFilePathToFile(string $filePath): File
4636 * @return Node[]
4737 */
4838 public function parseFileToDecoratedNodes (string $ filePath ): array
39+ {
40+ [$ file , $ stmts ] = $ this ->parseToFileAndStmts ($ filePath );
41+
42+ return $ stmts ;
43+ }
44+
45+ /**
46+ * @return array{0: File, 1: Node[]}
47+ */
48+ private function parseToFileAndStmts (string $ filePath ): array
4949 {
5050 // needed for PHPStan reflection, as it caches the last processed file
5151 $ this ->dynamicSourceLocatorProvider ->setFilePath ($ filePath );
5252
5353 $ fileContent = FileSystem::read ($ filePath );
54- $ stmts = $ this ->rectorParser ->parseString ($ fileContent );
5554 $ file = new File ($ filePath , $ fileContent );
5655
56+ $ stmts = $ this ->rectorParser ->parseString ($ fileContent );
5757 $ stmts = $ this ->nodeScopeAndMetadataDecorator ->decorateNodesFromFile ($ filePath , $ stmts );
58- $ file ->hydrateStmtsAndTokens ($ stmts , $ stmts , []);
5958
59+ $ file ->hydrateStmtsAndTokens ($ stmts , $ stmts , []);
6060 $ this ->currentFileProvider ->setFile ($ file );
6161
62- return $ stmts ;
62+ return [ $ file , $ stmts] ;
6363 }
6464}
0 commit comments