1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00
psalm/tests/Internal/Provider/ClassLikeStorageInstanceCacheProvider.php

42 lines
1.1 KiB
PHP
Raw Permalink 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
use Psalm\Storage\ClassLikeStorage;
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()
{
}
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) {
throw new \UnexpectedValueException('Should be in cache');
}
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;
}
}