2018-09-28 22:18:45 +02:00
|
|
|
<?php
|
2018-11-06 03:57:36 +01:00
|
|
|
namespace Psalm\Internal\Provider;
|
2018-09-28 22:18:45 +02:00
|
|
|
|
2019-06-26 22:52:29 +02:00
|
|
|
use const DIRECTORY_SEPARATOR;
|
2019-07-05 22:24:00 +02:00
|
|
|
use function file_exists;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function file_get_contents;
|
|
|
|
use function file_put_contents;
|
2019-07-05 22:24:00 +02:00
|
|
|
use function is_array;
|
|
|
|
use function is_readable;
|
|
|
|
use Psalm\Config;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function serialize;
|
2019-07-05 22:24:00 +02:00
|
|
|
use function unserialize;
|
2018-09-28 22:18:45 +02:00
|
|
|
|
|
|
|
/**
|
2020-05-15 06:16:20 +02:00
|
|
|
* @psalm-import-type FileMapType from \Psalm\Internal\Codebase\Analyzer
|
|
|
|
*
|
2018-09-28 22:18:45 +02:00
|
|
|
* Used to determine which files reference other files, necessary for using the --diff
|
|
|
|
* option from the command line.
|
|
|
|
*/
|
|
|
|
class FileReferenceCacheProvider
|
|
|
|
{
|
2020-09-20 18:54:46 +02:00
|
|
|
private const REFERENCE_CACHE_NAME = 'references';
|
|
|
|
private const CLASSLIKE_FILE_CACHE_NAME = 'classlike_files';
|
|
|
|
private const NONMETHOD_CLASS_REFERENCE_CACHE_NAME = 'file_class_references';
|
|
|
|
private const METHOD_CLASS_REFERENCE_CACHE_NAME = 'method_class_references';
|
|
|
|
private const ANALYZED_METHODS_CACHE_NAME = 'analyzed_methods';
|
|
|
|
private const CLASS_METHOD_CACHE_NAME = 'class_method_references';
|
|
|
|
private const FILE_CLASS_MEMBER_CACHE_NAME = 'file_class_member_references';
|
|
|
|
private const ISSUES_CACHE_NAME = 'issues';
|
|
|
|
private const FILE_MAPS_CACHE_NAME = 'file_maps';
|
|
|
|
private const TYPE_COVERAGE_CACHE_NAME = 'type_coverage';
|
|
|
|
private const CONFIG_HASH_CACHE_NAME = 'config';
|
|
|
|
private const METHOD_MISSING_MEMBER_CACHE_NAME = 'method_missing_member';
|
|
|
|
private const FILE_MISSING_MEMBER_CACHE_NAME = 'file_missing_member';
|
|
|
|
private const UNKNOWN_MEMBER_CACHE_NAME = 'unknown_member_references';
|
|
|
|
private const METHOD_PARAM_USE_CACHE_NAME = 'method_param_uses';
|
2018-09-28 22:18:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Config
|
|
|
|
*/
|
2020-06-06 18:24:16 +02:00
|
|
|
protected $config;
|
2018-09-28 22:18:45 +02:00
|
|
|
|
|
|
|
public function __construct(Config $config)
|
|
|
|
{
|
|
|
|
$this->config = $config;
|
2020-06-05 18:09:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function hasConfigChanged() : bool
|
|
|
|
{
|
|
|
|
$has_changed = $this->config->hash !== $this->getConfigHashCache();
|
|
|
|
$this->setConfigHashCache($this->config->hash);
|
|
|
|
return $has_changed;
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @psalm-suppress MixedAssignment
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getCachedFileReferences(): ?array
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
2020-06-05 18:09:38 +02:00
|
|
|
if (!$cache_directory) {
|
2018-09-28 22:18:45 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reference_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::REFERENCE_CACHE_NAME;
|
|
|
|
|
|
|
|
if (!is_readable($reference_cache_location)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reference_cache = unserialize((string) file_get_contents($reference_cache_location));
|
|
|
|
|
|
|
|
if (!is_array($reference_cache)) {
|
|
|
|
throw new \UnexpectedValueException('The reference cache must be an array');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $reference_cache;
|
|
|
|
}
|
|
|
|
|
2019-04-28 18:36:24 +02:00
|
|
|
/**
|
|
|
|
* @psalm-suppress MixedAssignment
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getCachedClassLikeFiles(): ?array
|
2020-04-02 23:17:55 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
2020-06-05 18:09:38 +02:00
|
|
|
if (!$cache_directory) {
|
2020-04-02 23:17:55 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reference_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::CLASSLIKE_FILE_CACHE_NAME;
|
|
|
|
|
|
|
|
if (!is_readable($reference_cache_location)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reference_cache = unserialize((string) file_get_contents($reference_cache_location));
|
|
|
|
|
|
|
|
if (!is_array($reference_cache)) {
|
|
|
|
throw new \UnexpectedValueException('The reference cache must be an array');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $reference_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @psalm-suppress MixedAssignment
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getCachedNonMethodClassReferences(): ?array
|
2019-04-28 18:36:24 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-04-02 23:17:55 +02:00
|
|
|
$reference_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::NONMETHOD_CLASS_REFERENCE_CACHE_NAME;
|
2019-04-28 18:36:24 +02:00
|
|
|
|
|
|
|
if (!is_readable($reference_cache_location)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reference_cache = unserialize((string) file_get_contents($reference_cache_location));
|
|
|
|
|
|
|
|
if (!is_array($reference_cache)) {
|
|
|
|
throw new \UnexpectedValueException('The reference cache must be an array');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $reference_cache;
|
|
|
|
}
|
|
|
|
|
2020-03-26 17:35:27 +01:00
|
|
|
/**
|
|
|
|
* @psalm-suppress MixedAssignment
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getCachedMethodClassReferences(): ?array
|
2020-03-26 17:35:27 +01:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::METHOD_CLASS_REFERENCE_CACHE_NAME;
|
|
|
|
|
|
|
|
if (!is_readable($cache_location)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reference_cache = unserialize((string) file_get_contents($cache_location));
|
|
|
|
|
|
|
|
if (!is_array($reference_cache)) {
|
|
|
|
throw new \UnexpectedValueException('The reference cache must be an array');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $reference_cache;
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:18:45 +02:00
|
|
|
/**
|
|
|
|
* @psalm-suppress MixedAssignment
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getCachedMethodMemberReferences(): ?array
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-04-13 00:28:07 +02:00
|
|
|
$class_member_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::CLASS_METHOD_CACHE_NAME;
|
2018-09-28 22:18:45 +02:00
|
|
|
|
2019-04-13 00:28:07 +02:00
|
|
|
if (!is_readable($class_member_cache_location)) {
|
2018-09-28 22:18:45 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-04-13 00:28:07 +02:00
|
|
|
$class_member_reference_cache = unserialize((string) file_get_contents($class_member_cache_location));
|
2018-09-28 22:18:45 +02:00
|
|
|
|
2019-04-13 00:28:07 +02:00
|
|
|
if (!is_array($class_member_reference_cache)) {
|
2018-09-28 22:18:45 +02:00
|
|
|
throw new \UnexpectedValueException('The reference cache must be an array');
|
|
|
|
}
|
|
|
|
|
2019-04-13 00:28:07 +02:00
|
|
|
return $class_member_reference_cache;
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
|
|
|
|
2019-04-16 22:07:48 +02:00
|
|
|
/**
|
|
|
|
* @psalm-suppress MixedAssignment
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getCachedMethodMissingMemberReferences(): ?array
|
2019-04-16 22:07:48 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$class_member_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::METHOD_MISSING_MEMBER_CACHE_NAME;
|
|
|
|
|
|
|
|
if (!is_readable($class_member_cache_location)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$class_member_reference_cache = unserialize((string) file_get_contents($class_member_cache_location));
|
|
|
|
|
|
|
|
if (!is_array($class_member_reference_cache)) {
|
|
|
|
throw new \UnexpectedValueException('The reference cache must be an array');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $class_member_reference_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @psalm-suppress MixedAssignment
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getCachedFileMemberReferences(): ?array
|
2019-04-16 22:07:48 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$file_class_member_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::FILE_CLASS_MEMBER_CACHE_NAME;
|
|
|
|
|
|
|
|
if (!is_readable($file_class_member_cache_location)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$file_class_member_reference_cache = unserialize((string) file_get_contents($file_class_member_cache_location));
|
|
|
|
|
|
|
|
if (!is_array($file_class_member_reference_cache)) {
|
|
|
|
throw new \UnexpectedValueException('The reference cache must be an array');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $file_class_member_reference_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @psalm-suppress MixedAssignment
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getCachedFileMissingMemberReferences(): ?array
|
2019-04-16 22:07:48 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$file_class_member_cache_location
|
|
|
|
= $cache_directory . DIRECTORY_SEPARATOR . self::FILE_MISSING_MEMBER_CACHE_NAME;
|
|
|
|
|
|
|
|
if (!is_readable($file_class_member_cache_location)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$file_class_member_reference_cache = unserialize((string) file_get_contents($file_class_member_cache_location));
|
|
|
|
|
|
|
|
if (!is_array($file_class_member_reference_cache)) {
|
|
|
|
throw new \UnexpectedValueException('The reference cache must be an array');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $file_class_member_reference_cache;
|
|
|
|
}
|
|
|
|
|
2019-04-27 23:38:24 +02:00
|
|
|
/**
|
|
|
|
* @psalm-suppress MixedAssignment
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getCachedMixedMemberNameReferences(): ?array
|
2019-04-27 23:38:24 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::UNKNOWN_MEMBER_CACHE_NAME;
|
|
|
|
|
|
|
|
if (!is_readable($cache_location)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache = unserialize((string) file_get_contents($cache_location));
|
|
|
|
|
|
|
|
if (!is_array($cache)) {
|
|
|
|
throw new \UnexpectedValueException('The reference cache must be an array');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cache;
|
|
|
|
}
|
|
|
|
|
2019-04-29 23:29:38 +02:00
|
|
|
/**
|
|
|
|
* @psalm-suppress MixedAssignment
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getCachedMethodParamUses(): ?array
|
2019-04-29 23:29:38 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::METHOD_PARAM_USE_CACHE_NAME;
|
|
|
|
|
|
|
|
if (!is_readable($cache_location)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache = unserialize((string) file_get_contents($cache_location));
|
|
|
|
|
|
|
|
if (!is_array($cache)) {
|
|
|
|
throw new \UnexpectedValueException('The method param use cache must be an array');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cache;
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:18:45 +02:00
|
|
|
/**
|
|
|
|
* @psalm-suppress MixedAssignment
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getCachedIssues(): ?array
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$issues_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::ISSUES_CACHE_NAME;
|
|
|
|
|
|
|
|
if (!is_readable($issues_cache_location)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$issues_cache = unserialize((string) file_get_contents($issues_cache_location));
|
|
|
|
|
|
|
|
if (!is_array($issues_cache)) {
|
|
|
|
throw new \UnexpectedValueException('The reference cache must be an array');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $issues_cache;
|
|
|
|
}
|
|
|
|
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setCachedFileReferences(array $file_references): void
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reference_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::REFERENCE_CACHE_NAME;
|
|
|
|
|
|
|
|
file_put_contents($reference_cache_location, serialize($file_references));
|
|
|
|
}
|
|
|
|
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setCachedClassLikeFiles(array $file_references): void
|
2020-04-02 23:17:55 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reference_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::CLASSLIKE_FILE_CACHE_NAME;
|
|
|
|
|
|
|
|
file_put_contents($reference_cache_location, serialize($file_references));
|
|
|
|
}
|
|
|
|
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setCachedNonMethodClassReferences(array $file_class_references): void
|
2019-04-28 18:36:24 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-02 23:17:55 +02:00
|
|
|
$reference_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::NONMETHOD_CLASS_REFERENCE_CACHE_NAME;
|
2019-04-28 18:36:24 +02:00
|
|
|
|
|
|
|
file_put_contents($reference_cache_location, serialize($file_class_references));
|
|
|
|
}
|
|
|
|
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setCachedMethodClassReferences(array $method_class_references): void
|
2020-03-26 17:35:27 +01:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reference_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::METHOD_CLASS_REFERENCE_CACHE_NAME;
|
|
|
|
|
|
|
|
file_put_contents($reference_cache_location, serialize($method_class_references));
|
|
|
|
}
|
|
|
|
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setCachedMethodMemberReferences(array $member_references): void
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-13 00:28:07 +02:00
|
|
|
$member_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::CLASS_METHOD_CACHE_NAME;
|
2018-09-28 22:18:45 +02:00
|
|
|
|
2019-04-16 22:07:48 +02:00
|
|
|
file_put_contents($member_cache_location, serialize($member_references));
|
|
|
|
}
|
|
|
|
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setCachedMethodMissingMemberReferences(array $member_references): void
|
2019-04-16 22:07:48 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$member_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::METHOD_MISSING_MEMBER_CACHE_NAME;
|
|
|
|
|
|
|
|
file_put_contents($member_cache_location, serialize($member_references));
|
|
|
|
}
|
|
|
|
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setCachedFileMemberReferences(array $member_references): void
|
2019-04-16 22:07:48 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$member_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::FILE_CLASS_MEMBER_CACHE_NAME;
|
|
|
|
|
|
|
|
file_put_contents($member_cache_location, serialize($member_references));
|
|
|
|
}
|
|
|
|
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setCachedFileMissingMemberReferences(array $member_references): void
|
2019-04-16 22:07:48 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$member_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::FILE_MISSING_MEMBER_CACHE_NAME;
|
|
|
|
|
2019-04-13 00:28:07 +02:00
|
|
|
file_put_contents($member_cache_location, serialize($member_references));
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
|
|
|
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setCachedMixedMemberNameReferences(array $references): void
|
2019-04-27 23:38:24 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::UNKNOWN_MEMBER_CACHE_NAME;
|
|
|
|
|
2019-04-29 23:29:38 +02:00
|
|
|
file_put_contents($cache_location, serialize($references));
|
|
|
|
}
|
|
|
|
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setCachedMethodParamUses(array $uses): void
|
2019-04-29 23:29:38 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::METHOD_PARAM_USE_CACHE_NAME;
|
|
|
|
|
2020-08-10 05:19:59 +02:00
|
|
|
file_put_contents($cache_location, serialize($uses));
|
2019-04-27 23:38:24 +02:00
|
|
|
}
|
|
|
|
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setCachedIssues(array $issues): void
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$issues_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::ISSUES_CACHE_NAME;
|
|
|
|
|
|
|
|
file_put_contents($issues_cache_location, serialize($issues));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-07 04:58:21 +02:00
|
|
|
* @return array<string, array<string, int>>|false
|
2018-09-28 22:18:45 +02:00
|
|
|
*/
|
2018-11-02 02:52:39 +01:00
|
|
|
public function getAnalyzedMethodCache()
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
2018-10-07 02:11:19 +02:00
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
2018-09-28 22:18:45 +02:00
|
|
|
|
2018-11-02 02:52:39 +01:00
|
|
|
$analyzed_methods_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::ANALYZED_METHODS_CACHE_NAME;
|
2018-09-28 22:18:45 +02:00
|
|
|
|
|
|
|
if ($cache_directory
|
2018-11-02 02:52:39 +01:00
|
|
|
&& file_exists($analyzed_methods_cache_location)
|
2018-09-28 22:18:45 +02:00
|
|
|
) {
|
2018-10-07 04:58:21 +02:00
|
|
|
/** @var array<string, array<string, int>> */
|
2018-11-02 02:52:39 +01:00
|
|
|
return unserialize(file_get_contents($analyzed_methods_cache_location));
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
|
|
|
|
2018-10-07 02:11:19 +02:00
|
|
|
return false;
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-02 02:52:39 +01:00
|
|
|
* @param array<string, array<string, int>> $analyzed_methods
|
2018-09-28 22:18:45 +02:00
|
|
|
*/
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setAnalyzedMethodCache(array $analyzed_methods): void
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
|
|
|
$cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
if ($cache_directory) {
|
2018-11-02 02:52:39 +01:00
|
|
|
$analyzed_methods_cache_location = $cache_directory
|
|
|
|
. DIRECTORY_SEPARATOR
|
|
|
|
. self::ANALYZED_METHODS_CACHE_NAME;
|
2018-09-28 22:18:45 +02:00
|
|
|
|
|
|
|
file_put_contents(
|
2018-11-02 02:52:39 +01:00
|
|
|
$analyzed_methods_cache_location,
|
|
|
|
serialize($analyzed_methods)
|
2018-09-28 22:18:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-10-26 22:17:15 +02:00
|
|
|
|
|
|
|
/**
|
2020-05-15 06:16:20 +02:00
|
|
|
* @return array<string, FileMapType>|false
|
2018-10-26 22:17:15 +02:00
|
|
|
*/
|
|
|
|
public function getFileMapCache()
|
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
$file_maps_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::FILE_MAPS_CACHE_NAME;
|
|
|
|
|
|
|
|
if ($cache_directory
|
|
|
|
&& file_exists($file_maps_cache_location)
|
|
|
|
) {
|
2019-06-21 23:10:35 +02:00
|
|
|
/**
|
2020-05-15 06:16:20 +02:00
|
|
|
* @var array<string, FileMapType>
|
2019-06-21 23:10:35 +02:00
|
|
|
*/
|
2018-10-26 22:17:15 +02:00
|
|
|
$file_maps_cache = unserialize(file_get_contents($file_maps_cache_location));
|
2019-07-05 22:24:00 +02:00
|
|
|
|
2018-10-26 22:17:15 +02:00
|
|
|
return $file_maps_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-15 06:16:20 +02:00
|
|
|
* @param array<string, FileMapType> $file_maps
|
2018-10-26 22:17:15 +02:00
|
|
|
*/
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setFileMapCache(array $file_maps): void
|
2018-10-26 22:17:15 +02:00
|
|
|
{
|
|
|
|
$cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
if ($cache_directory) {
|
|
|
|
$file_maps_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::FILE_MAPS_CACHE_NAME;
|
|
|
|
|
|
|
|
file_put_contents(
|
|
|
|
$file_maps_cache_location,
|
|
|
|
serialize($file_maps)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-03-23 14:50:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<string, array{int, int}>|false
|
|
|
|
*/
|
|
|
|
public function getTypeCoverage()
|
|
|
|
{
|
|
|
|
$cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
$type_coverage_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::TYPE_COVERAGE_CACHE_NAME;
|
|
|
|
|
|
|
|
if ($cache_directory
|
|
|
|
&& file_exists($type_coverage_cache_location)
|
|
|
|
) {
|
|
|
|
/** @var array<string, array{int, int}> */
|
|
|
|
$type_coverage_cache = unserialize(file_get_contents($type_coverage_cache_location));
|
2019-07-05 22:24:00 +02:00
|
|
|
|
2019-03-23 14:50:47 +01:00
|
|
|
return $type_coverage_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<string, array{int, int}> $mixed_counts
|
|
|
|
*/
|
2020-10-12 21:02:52 +02:00
|
|
|
public function setTypeCoverage(array $mixed_counts): void
|
2019-03-23 14:50:47 +01:00
|
|
|
{
|
|
|
|
$cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
if ($cache_directory) {
|
|
|
|
$type_coverage_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::TYPE_COVERAGE_CACHE_NAME;
|
|
|
|
|
|
|
|
file_put_contents(
|
|
|
|
$type_coverage_cache_location,
|
|
|
|
serialize($mixed_counts)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-11-01 22:42:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string|false
|
|
|
|
*/
|
|
|
|
public function getConfigHashCache()
|
|
|
|
{
|
|
|
|
$cache_directory = $this->config->getCacheDirectory();
|
|
|
|
|
|
|
|
$config_hash_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::CONFIG_HASH_CACHE_NAME;
|
|
|
|
|
|
|
|
if ($cache_directory
|
|
|
|
&& file_exists($config_hash_cache_location)
|
|
|
|
) {
|
|
|
|
/** @var string */
|
2020-06-05 18:09:38 +02:00
|
|
|
$file_maps_cache = file_get_contents($config_hash_cache_location);
|
2019-07-05 22:24:00 +02:00
|
|
|
|
2018-11-01 22:42:48 +01:00
|
|
|
return $file_maps_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-12 17:24:05 +02:00
|
|
|
public function setConfigHashCache(string $hash): void
|
2018-11-01 22:42:48 +01:00
|
|
|
{
|
|
|
|
$cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
if ($cache_directory) {
|
2019-07-11 17:07:39 +02:00
|
|
|
if (!file_exists($cache_directory)) {
|
|
|
|
\mkdir($cache_directory, 0777, true);
|
2019-07-11 16:46:12 +02:00
|
|
|
}
|
|
|
|
|
2018-11-01 22:42:48 +01:00
|
|
|
$config_hash_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::CONFIG_HASH_CACHE_NAME;
|
|
|
|
|
|
|
|
file_put_contents(
|
|
|
|
$config_hash_cache_location,
|
2020-06-05 18:09:38 +02:00
|
|
|
$hash
|
2018-11-01 22:42:48 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|