2018-09-28 22:18:45 +02:00
|
|
|
<?php
|
2018-11-12 16:57:05 +01:00
|
|
|
namespace Psalm\Tests\Internal\Provider;
|
2018-09-28 22:18:45 +02:00
|
|
|
|
2019-06-26 22:52:29 +02:00
|
|
|
use function microtime;
|
2019-07-05 22:24:00 +02:00
|
|
|
use PhpParser;
|
2018-09-28 22:18:45 +02:00
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
class ParserInstanceCacheProvider extends \Psalm\Internal\Provider\ParserCacheProvider
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
|
|
|
private $file_contents_cache = [];
|
|
|
|
|
2018-10-26 06:59:14 +02:00
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
|
|
|
private $file_content_hash = [];
|
|
|
|
|
2018-09-28 22:18:45 +02:00
|
|
|
/**
|
2019-10-09 01:06:16 +02:00
|
|
|
* @var array<string, list<PhpParser\Node\Stmt>>
|
2018-09-28 22:18:45 +02:00
|
|
|
*/
|
|
|
|
private $statements_cache = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array<string, float>
|
|
|
|
*/
|
|
|
|
private $statements_cache_time = [];
|
|
|
|
|
2018-10-16 21:59:11 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function loadStatementsFromCache($file_path, $file_modified_time, $file_content_hash)
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
2018-10-16 21:59:11 +02:00
|
|
|
if (isset($this->statements_cache[$file_path])
|
|
|
|
&& $this->statements_cache_time[$file_path] >= $file_modified_time
|
2018-10-26 06:59:14 +02:00
|
|
|
&& $this->file_content_hash[$file_path] === $file_content_hash
|
2018-09-28 22:18:45 +02:00
|
|
|
) {
|
2018-10-16 21:59:11 +02:00
|
|
|
return $this->statements_cache[$file_path];
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_content_hash
|
2018-10-16 21:59:11 +02:00
|
|
|
* @param string $file_path
|
2018-09-28 22:18:45 +02:00
|
|
|
* @param mixed $file_modified_time
|
|
|
|
*
|
2019-10-09 01:06:16 +02:00
|
|
|
* @return list<PhpParser\Node\Stmt>|null
|
2018-09-28 22:18:45 +02:00
|
|
|
*/
|
2018-10-16 21:59:11 +02:00
|
|
|
public function loadExistingStatementsFromCache($file_path)
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
2018-10-16 21:59:11 +02:00
|
|
|
if (isset($this->statements_cache[$file_path])) {
|
|
|
|
return $this->statements_cache[$file_path];
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-16 21:59:11 +02:00
|
|
|
* @param string $file_path
|
2018-09-28 22:18:45 +02:00
|
|
|
* @param string $file_content_hash
|
2019-10-09 01:06:16 +02:00
|
|
|
* @param list<PhpParser\Node\Stmt> $stmts
|
2018-09-28 22:18:45 +02:00
|
|
|
* @param bool $touch_only
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-10-16 21:59:11 +02:00
|
|
|
public function saveStatementsToCache($file_path, $file_content_hash, array $stmts, $touch_only)
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
2018-10-16 21:59:11 +02:00
|
|
|
$this->statements_cache[$file_path] = $stmts;
|
|
|
|
$this->statements_cache_time[$file_path] = microtime(true);
|
2018-10-26 06:59:14 +02:00
|
|
|
$this->file_content_hash[$file_path] = $file_content_hash;
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-16 21:59:11 +02:00
|
|
|
* @param string $file_path
|
2018-09-28 22:18:45 +02:00
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
*/
|
2018-10-16 21:59:11 +02:00
|
|
|
public function loadExistingFileContentsFromCache($file_path)
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
2018-10-16 21:59:11 +02:00
|
|
|
if (isset($this->file_contents_cache[$file_path])) {
|
|
|
|
return $this->file_contents_cache[$file_path];
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-16 21:59:11 +02:00
|
|
|
* @param string $file_path
|
2018-09-28 22:18:45 +02:00
|
|
|
* @param string $file_contents
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-10-16 21:59:11 +02:00
|
|
|
public function cacheFileContents($file_path, $file_contents)
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
2018-10-16 21:59:11 +02:00
|
|
|
$this->file_contents_cache[$file_path] = $file_contents;
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
2020-06-06 22:57:25 +02:00
|
|
|
|
|
|
|
public function saveFileContentHashes()
|
|
|
|
{
|
|
|
|
}
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|