77use PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
88use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator;
99use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocatorFactory;
10- use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocatorFactory;
1110use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocatorRepository;
1211use Rector\Contract\DependencyInjection\ResettableInterface;
1312use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
@@ -31,8 +30,7 @@ final class DynamicSourceLocatorProvider implements ResettableInterface
3130
3231 public function __construct(
3332 private readonly OptimizedDirectorySourceLocatorFactory $optimizedDirectorySourceLocatorFactory,
34- private readonly OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository,
35- private readonly OptimizedSingleFileSourceLocatorFactory $optimizedSingleFileSourceLocatorFactory
33+ private readonly OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository
3634 ) {
3735 }
3836
@@ -69,12 +67,7 @@ public function provide(): SourceLocator
6967 $sourceLocators = [];
7068
7169 foreach ($this->filePaths as $file) {
72- // under PHPUnit each fixture is a throwaway temp file that is deleted after the test;
73- // the shared repository caches locators by path forever, so a stale locator for a since-deleted
74- // file can leak into a later test. build a fresh locator per run there, keep caching in production
75- $sourceLocators[] = $isPHPUnitRun
76- ? $this->optimizedSingleFileSourceLocatorFactory->create($file)
77- : $this->optimizedSingleFileSourceLocatorRepository->getOrCreate($file);
70+ $sourceLocators[] = $this->optimizedSingleFileSourceLocatorRepository->getOrCreate($file);
7871 }
7972
8073 foreach ($this->directories as $directory) {
0 commit comments