Skip to content
Merged
Show file tree
Hide file tree
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 @@ -129,7 +129,7 @@ public function create(string $projectInstallationPath): ?SourceLocator
}

if (count($files) > 0) {
$locators[] = $this->optimizedDirectorySourceLocatorFactory->createByFiles($files);
$locators[] = $this->optimizedDirectorySourceLocatorFactory->createByFiles($files, 'odsl-installed-files');
}

$binDir = ComposerHelper::getBinDirFromComposerConfig($projectInstallationPath, $composer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ public function createByDirectory(string $directory): OptimizedDirectorySourceLo
}

$cacheKey = sprintf('odsl-%s', $directory);
return $this->createCachedDirectorySourceLocator($fileHashes, $cacheKey);
}

/**
* @param array<string, string> $fileHashes
* @param non-empty-string $cacheKey
*/
private function createCachedDirectorySourceLocator(array $fileHashes, string $cacheKey): OptimizedDirectorySourceLocator
{
$variableCacheKey = 'v1';

/** @var array<string, array{string, string[], string[], string[]}>|null $cached */
Expand Down Expand Up @@ -93,23 +102,20 @@ public function createByDirectory(string $directory): OptimizedDirectorySourceLo

/**
* @param string[] $files
* @param non-empty-string&literal-string $uniqueCacheIdentifier
*/
public function createByFiles(array $files): OptimizedDirectorySourceLocator
public function createByFiles(array $files, string $uniqueCacheIdentifier): OptimizedDirectorySourceLocator
{
$symbols = [];
$fileHashes = [];
foreach ($files as $file) {
[$newClasses, $newFunctions, $newConstants] = $this->findSymbols($file);
$symbols[$file] = ['', $newClasses, $newFunctions, $newConstants];
$hash = sha1_file($file);
if ($hash === false) {
continue;
}
$fileHashes[$file] = $hash;
}

[$classToFile, $functionToFiles, $constantToFile] = $this->changeStructure($symbols);

return new OptimizedDirectorySourceLocator(
$this->fileNodesFetcher,
$classToFile,
$functionToFiles,
$constantToFile,
);
return $this->createCachedDirectorySourceLocator($fileHashes, $uniqueCacheIdentifier);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function testFunctionDoesNotExist(string $functionName): void
public function testBug5525(): void
{
$factory = self::getContainer()->getByType(OptimizedDirectorySourceLocatorFactory::class);
$locator = $factory->createByFiles([__DIR__ . '/data/bug-5525.php']);
$locator = $factory->createByFiles([__DIR__ . '/data/bug-5525.php'], 'bug5525-odsl-installed-files');
$reflector = new DefaultReflector($locator);

$class = $reflector->reflectClass('Faker\\Provider\\nl_BE\\Text');
Expand Down
Loading