1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 09:19:40 +01:00
psalm/tests/Internal/Provider/FileStorageInstanceCacheProvider.php

46 lines
1.1 KiB
PHP
Raw Normal View History

2018-10-12 05:00:32 +02:00
<?php
namespace Psalm\Tests\Internal\Provider;
2018-10-12 05:00:32 +02:00
2021-12-03 20:11:20 +01:00
use Psalm\Internal\Provider\FileStorageCacheProvider;
2018-10-12 05:00:32 +02:00
use Psalm\Storage\FileStorage;
2021-06-08 04:55:21 +02:00
use function strtolower;
2018-10-12 05:00:32 +02:00
2021-12-03 20:11:20 +01:00
class FileStorageInstanceCacheProvider extends FileStorageCacheProvider
2018-10-12 05:00:32 +02:00
{
/** @var array<lowercase-string, FileStorage> */
2022-12-16 19:58:47 +01:00
private array $cache = [];
2018-10-12 05:00:32 +02:00
public function __construct()
{
}
public function writeToCache(FileStorage $storage, string $file_contents): void
2018-10-12 05:00:32 +02:00
{
$file_path = strtolower($storage->file_path);
$this->cache[$file_path] = $storage;
}
public function getLatestFromCache(string $file_path, string $file_contents): ?FileStorage
2018-10-12 05:00:32 +02:00
{
$cached_value = $this->loadFromCache(strtolower($file_path));
if (!$cached_value) {
return null;
}
return $cached_value;
}
public function removeCacheForFile(string $file_path): void
2018-10-12 05:00:32 +02:00
{
unset($this->cache[strtolower($file_path)]);
}
private function loadFromCache(string $file_path): ?FileStorage
2018-10-12 05:00:32 +02:00
{
return $this->cache[strtolower($file_path)] ?? null;
}
}