diff --git a/src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php b/src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php index 8e5275cbb9e..f5fc2e9dd12 100644 --- a/src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php +++ b/src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php @@ -7,7 +7,6 @@ use PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator; use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator; use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocatorFactory; -use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocatorFactory; use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocatorRepository; use Rector\Contract\DependencyInjection\ResettableInterface; use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment; @@ -31,8 +30,7 @@ final class DynamicSourceLocatorProvider implements ResettableInterface public function __construct( private readonly OptimizedDirectorySourceLocatorFactory $optimizedDirectorySourceLocatorFactory, - private readonly OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository, - private readonly OptimizedSingleFileSourceLocatorFactory $optimizedSingleFileSourceLocatorFactory + private readonly OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository ) { } @@ -69,12 +67,7 @@ public function provide(): SourceLocator $sourceLocators = []; foreach ($this->filePaths as $file) { - // under PHPUnit each fixture is a throwaway temp file that is deleted after the test; - // the shared repository caches locators by path forever, so a stale locator for a since-deleted - // file can leak into a later test. build a fresh locator per run there, keep caching in production - $sourceLocators[] = $isPHPUnitRun - ? $this->optimizedSingleFileSourceLocatorFactory->create($file) - : $this->optimizedSingleFileSourceLocatorRepository->getOrCreate($file); + $sourceLocators[] = $this->optimizedSingleFileSourceLocatorRepository->getOrCreate($file); } foreach ($this->directories as $directory) {