File tree Expand file tree Collapse file tree 3 files changed +11
-1
lines changed
Reflection/BetterReflection Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Original file line number Diff line number Diff line change 1616final class PathRoutingParser implements Parser
1717{
1818
19+ private ?string $ singleReflectionFile ;
20+
1921 /** @var bool[] filePath(string) => bool(true) */
2022 private array $ analysedFiles = [];
2123
@@ -24,8 +26,10 @@ public function __construct(
2426 private Parser $ currentPhpVersionRichParser ,
2527 private Parser $ currentPhpVersionSimpleParser ,
2628 private Parser $ php8Parser ,
29+ ?string $ singleReflectionFile ,
2730 )
2831 {
32+ $ this ->singleReflectionFile = $ singleReflectionFile !== null ? $ fileHelper ->normalizePath ($ singleReflectionFile ) : null ;
2933 }
3034
3135 /**
@@ -47,7 +51,7 @@ public function parseFile(string $file): array
4751 }
4852
4953 $ file = $ this ->fileHelper ->normalizePath ($ file );
50- if (!isset ($ this ->analysedFiles [$ file ])) {
54+ if (!isset ($ this ->analysedFiles [$ file ]) && $ file !== $ this -> singleReflectionFile ) {
5155 // check symlinked file that still might be in analysedFiles
5256 $ pathParts = explode (DIRECTORY_SEPARATOR , $ file );
5357 for ($ i = count ($ pathParts ); $ i > 1 ; $ i --) {
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ public function __construct(
5656 private array $ composerAutoloaderProjectPaths ,
5757 private array $ analysedPathsFromConfig ,
5858 private bool $ playgroundMode , // makes all PHPStan classes in the PHAR discoverable with PSR-4
59+ private ?string $ singleReflectionFile ,
5960 )
6061 {
6162 }
@@ -64,6 +65,10 @@ public function create(): SourceLocator
6465 {
6566 $ locators = [];
6667
68+ if ($ this ->singleReflectionFile !== null ) {
69+ $ locators [] = $ this ->optimizedSingleFileSourceLocatorRepository ->getOrCreate ($ this ->singleReflectionFile );
70+ }
71+
6772 $ astLocator = new Locator ($ this ->parser );
6873 $ locators [] = new AutoloadFunctionsSourceLocator (
6974 new AutoloadSourceLocator ($ this ->fileNodesFetcher , false ),
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ public function testParseTheSameFileWithDifferentMethod(): void
8383 self ::getContainer ()->getService ('currentPhpVersionRichParser ' ),
8484 self ::getContainer ()->getService ('currentPhpVersionSimpleDirectParser ' ),
8585 self ::getContainer ()->getService ('php8Parser ' ),
86+ null ,
8687 );
8788 $ parser = new CachedParser ($ pathRoutingParser , 500 );
8889 $ path = $ fileHelper ->normalizePath (__DIR__ . '/data/test.php ' );
You can’t perform that action at this time.
0 commit comments