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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string|null $file_path
|
|
|
|
* @param string|null $file_contents
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-09-07 01:36:47 +02:00
|
|
|
public function writeToCache(ClassLikeStorage $storage, ?string $file_path, ?string $file_contents)
|
2018-10-12 05:00:32 +02:00
|
|
|
{
|
|
|
|
$fq_classlike_name_lc = strtolower($storage->name);
|
|
|
|
$this->cache[$fq_classlike_name_lc] = $storage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $fq_classlike_name_lc
|
|
|
|
* @param string|null $file_path
|
|
|
|
* @param string|null $file_contents
|
|
|
|
*
|
|
|
|
* @return ClassLikeStorage
|
|
|
|
*/
|
2020-09-07 01:36:47 +02:00
|
|
|
public function getLatestFromCache(string $fq_classlike_name_lc, ?string $file_path, ?string $file_contents)
|
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
|
|
|
|
*
|
|
|
|
* @return ClassLikeStorage|null
|
|
|
|
*/
|
|
|
|
private function loadFromCache($fq_classlike_name_lc)
|
|
|
|
{
|
|
|
|
return $this->cache[$fq_classlike_name_lc] ?? null;
|
|
|
|
}
|
|
|
|
}
|