1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-03 10:07:52 +01:00
psalm/tests/Internal/Provider/FileStorageInstanceCacheProvider.php
orklah 8c7423505a
add native param types (#4137)
* add native param types

* redundant phpdoc

* add more param types and adds "?" to nullable types

* remove redundant phpdoc

* add more param types and remove redundant phpdoc

* add more param types and remove redundant phpdoc
2020-09-06 19:36:47 -04:00

52 lines
1.1 KiB
PHP

<?php
namespace Psalm\Tests\Internal\Provider;
use Psalm\Storage\FileStorage;
use function strtolower;
class FileStorageInstanceCacheProvider extends \Psalm\Internal\Provider\FileStorageCacheProvider
{
/** @var array<string, FileStorage> */
private $cache = [];
public function __construct()
{
}
/**
* @return void
*/
public function writeToCache(FileStorage $storage, string $file_contents)
{
$file_path = strtolower($storage->file_path);
$this->cache[$file_path] = $storage;
}
public function getLatestFromCache(string $file_path, string $file_contents): ?FileStorage
{
$cached_value = $this->loadFromCache(strtolower($file_path));
if (!$cached_value) {
return null;
}
return $cached_value;
}
/**
* @return void
*/
public function removeCacheForFile(string $file_path)
{
unset($this->cache[strtolower($file_path)]);
}
/**
* @return FileStorage|null
*/
private function loadFromCache(string $file_path)
{
return $this->cache[strtolower($file_path)] ?? null;
}
}