Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down Expand Up @@ -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) {
Expand Down
Loading