1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00
psalm/tests/Internal/Provider/ClassLikeStorageInstanceCacheProvider.php
LeSuisse f29826b958 Fully qualify constants and function calls (#1849)
This should give a small performance boost.
Part of #1837.

The change is enforced via phpcs and can be autofixed
with phpcbf.
2019-06-26 16:52:29 -04:00

56 lines
1.4 KiB
PHP

<?php
namespace Psalm\Tests\Internal\Provider;
use Psalm\Storage\ClassLikeStorage;
use function strtolower;
class ClassLikeStorageInstanceCacheProvider extends \Psalm\Internal\Provider\ClassLikeStorageCacheProvider
{
/** @var array<string, ClassLikeStorage> */
private $cache = [];
public function __construct()
{
}
/**
* @param string|null $file_path
* @param string|null $file_contents
*
* @return void
*/
public function writeToCache(ClassLikeStorage $storage, $file_path, $file_contents)
{
$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
*/
public function getLatestFromCache($fq_classlike_name_lc, $file_path, $file_contents)
{
$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;
}
}