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

46 lines
1.2 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\ClassLikeStorageCacheProvider;
2018-10-12 05:00:32 +02:00
use Psalm\Storage\ClassLikeStorage;
2021-12-03 21:40:18 +01:00
use UnexpectedValueException;
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 ClassLikeStorageInstanceCacheProvider extends ClassLikeStorageCacheProvider
2018-10-12 05:00:32 +02:00
{
/** @var array<string, ClassLikeStorage> */
private $cache = [];
public function __construct()
{
}
public function writeToCache(ClassLikeStorage $storage, ?string $file_path, ?string $file_contents): void
2018-10-12 05:00:32 +02:00
{
$fq_classlike_name_lc = strtolower($storage->name);
$this->cache[$fq_classlike_name_lc] = $storage;
}
public function getLatestFromCache(string $fq_classlike_name_lc, ?string $file_path, ?string $file_contents): ClassLikeStorage
2018-10-12 05:00:32 +02:00
{
$cached_value = $this->loadFromCache($fq_classlike_name_lc);
if (!$cached_value) {
2021-12-03 21:40:18 +01:00
throw new UnexpectedValueException('Should be in cache');
2018-10-12 05:00:32 +02:00
}
return $cached_value;
}
/**
* @param string $fq_classlike_name_lc
*
*/
private function loadFromCache($fq_classlike_name_lc): ?ClassLikeStorage
2018-10-12 05:00:32 +02:00
{
return $this->cache[$fq_classlike_name_lc] ?? null;
}
}