@@ -28,20 +28,7 @@ public function __construct(
2828
2929 public function parseFilePathToFile (string $ filePath ): File
3030 {
31- // needed for PHPStan reflection, as it caches the last processed file
32- $ this ->dynamicSourceLocatorProvider ->setFilePath ($ filePath );
33-
34- $ fileContent = FileSystem::read ($ filePath );
35- $ file = new File ($ filePath , $ fileContent );
36- $ stmts = $ this ->rectorParser ->parseString ($ fileContent );
37-
38- // wrap in FileNode to enable file-level rules
39- $ stmts = [new FileNode ($ stmts )];
40-
41- $ stmts = $ this ->nodeScopeAndMetadataDecorator ->decorateNodesFromFile ($ filePath , $ stmts );
42-
43- $ file ->hydrateStmtsAndTokens ($ stmts , $ stmts , []);
44- $ this ->currentFileProvider ->setFile ($ file );
31+ [$ file , $ stmts ] = $ this ->parseToFileAndStmts ($ filePath );
4532
4633 return $ file ;
4734 }
@@ -50,22 +37,49 @@ public function parseFilePathToFile(string $filePath): File
5037 * @return Node[]
5138 */
5239 public function parseFileToDecoratedNodes (string $ filePath ): array
40+ {
41+ [$ file , $ stmts ] = $ this ->parseToFileAndStmts ($ filePath );
42+
43+ return $ stmts ;
44+ //
45+ // // needed for PHPStan reflection, as it caches the last processed file
46+ // $this->dynamicSourceLocatorProvider->setFilePath($filePath);
47+ //
48+ // $fileContent = FileSystem::read($filePath);
49+ // $stmts = $this->rectorParser->parseString($fileContent);
50+ // $file = new File($filePath, $fileContent);
51+ //
52+ // // wrap in FileNode to enable file-level rules
53+ // $stmts = [new FileNode($stmts)];
54+ //
55+ // $stmts = $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($filePath, $stmts);
56+ // $file->hydrateStmtsAndTokens($stmts, $stmts, []);
57+ //
58+ // $this->currentFileProvider->setFile($file);
59+ //
60+ // return $stmts;
61+ }
62+
63+ /**
64+ * @return array{0: File, 1: Node\Stmt[]}
65+ */
66+ private function parseToFileAndStmts (string $ filePath ): array
5367 {
5468 // needed for PHPStan reflection, as it caches the last processed file
5569 $ this ->dynamicSourceLocatorProvider ->setFilePath ($ filePath );
5670
5771 $ fileContent = FileSystem::read ($ filePath );
58- $ stmts = $ this ->rectorParser ->parseString ($ fileContent );
5972 $ file = new File ($ filePath , $ fileContent );
73+ $ stmts = $ this ->rectorParser ->parseString ($ fileContent );
6074
6175 // wrap in FileNode to enable file-level rules
6276 $ stmts = [new FileNode ($ stmts )];
6377
6478 $ stmts = $ this ->nodeScopeAndMetadataDecorator ->decorateNodesFromFile ($ filePath , $ stmts );
65- $ file ->hydrateStmtsAndTokens ($ stmts , $ stmts , []);
6679
80+ $ file ->hydrateStmtsAndTokens ($ stmts , $ stmts , []);
6781 $ this ->currentFileProvider ->setFile ($ file );
6882
69- return $ stmts ;
83+ return [ $ file , $ stmts] ;
7084 }
7185}
0 commit comments