2018-10-12 05:00:32 +02:00
|
|
|
<?php
|
2018-11-12 16:57:05 +01:00
|
|
|
namespace Psalm\Tests\Internal\Provider;
|
2018-10-12 05:00:32 +02:00
|
|
|
|
|
|
|
use Psalm\Storage\ClassLikeStorage;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function strtolower;
|
2018-10-12 05:00:32 +02:00
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
class ClassLikeStorageInstanceCacheProvider extends \Psalm\Internal\Provider\ClassLikeStorageCacheProvider
|
2018-10-12 05:00:32 +02:00
|
|
|
{
|
|
|
|
/** @var array<string, ClassLikeStorage> */
|
|
|
|
private $cache = [];
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-10-12 21:02:52 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
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) {
|
|
|
|
throw new \UnexpectedValueException('Should be in cache');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cached_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $fq_classlike_name_lc
|
|
|
|
*
|
|
|
|
*/
|
2020-09-12 17:24:05 +02:00
|
|
|
private function loadFromCache($fq_classlike_name_lc): ?ClassLikeStorage
|
2018-10-12 05:00:32 +02:00
|
|
|
{
|
|
|
|
return $this->cache[$fq_classlike_name_lc] ?? null;
|
|
|
|
}
|
|
|
|
}
|