Updated Rector to commit 687a77765f

687a77765f Added MemoryCacheStorage and use it in  (#525)
This commit is contained in:
Tomas Votruba 2021-07-28 07:05:44 +00:00
parent b8d4e57170
commit 0032287992
13 changed files with 153 additions and 40 deletions

View File

@ -3,6 +3,7 @@
declare (strict_types=1);
namespace RectorPrefix20210728;
use Rector\Caching\ValueObject\Storage\MemoryCacheStorage;
use Rector\Core\Configuration\Option;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator $containerConfigurator) : void {
@ -23,4 +24,10 @@ return static function (\Symfony\Component\DependencyInjection\Loader\Configurat
$parameters->set(\Rector\Core\Configuration\Option::PHPSTAN_FOR_RECTOR_PATH, null);
// cache
$parameters->set(\Rector\Core\Configuration\Option::CACHE_DIR, \sys_get_temp_dir() . '/rector_cached_files');
// use faster in-memory cache in CI.
// CI always starts from scratch, therefore IO intensive caching is not worth it
$runsInGithubAction = \getenv('GITHUB_ACTION');
if (\false !== $runsInGithubAction) {
$parameters->set(\Rector\Core\Configuration\Option::CACHE_CLASS, \Rector\Caching\ValueObject\Storage\MemoryCacheStorage::class);
}
};

View File

@ -3,37 +3,37 @@
declare (strict_types=1);
namespace Rector\Caching;
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Caching\ValueObject\Storage\CacheStorageInterface;
final class Cache
{
/**
* @var \Rector\Caching\ValueObject\Storage\FileCacheStorage
* @var \Rector\Caching\ValueObject\Storage\CacheStorageInterface
*/
private $fileCacheStorage;
public function __construct(\Rector\Caching\ValueObject\Storage\FileCacheStorage $fileCacheStorage)
private $cacheStorage;
public function __construct(\Rector\Caching\ValueObject\Storage\CacheStorageInterface $cacheStorage)
{
$this->fileCacheStorage = $fileCacheStorage;
$this->cacheStorage = $cacheStorage;
}
/**
* @return mixed|null
*/
public function load(string $key, string $variableKey)
{
return $this->fileCacheStorage->load($key, $variableKey);
return $this->cacheStorage->load($key, $variableKey);
}
/**
* @param mixed $data
*/
public function save(string $key, string $variableKey, $data) : void
{
$this->fileCacheStorage->save($key, $variableKey, $data);
$this->cacheStorage->save($key, $variableKey, $data);
}
public function clear() : void
{
$this->fileCacheStorage->clear();
$this->cacheStorage->clear();
}
public function clean(string $cacheKey) : void
{
$this->fileCacheStorage->clean($cacheKey);
$this->cacheStorage->clean($cacheKey);
}
}

View File

@ -3,7 +3,9 @@
declare (strict_types=1);
namespace Rector\Caching;
use Rector\Caching\ValueObject\Storage\CacheStorageInterface;
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Caching\ValueObject\Storage\MemoryCacheStorage;
use Rector\Core\Configuration\Option;
use RectorPrefix20210728\Symplify\PackageBuilder\Parameter\ParameterProvider;
use RectorPrefix20210728\Symplify\SmartFileSystem\SmartFileSystem;
@ -25,11 +27,18 @@ final class CacheFactory
public function create() : \Rector\Caching\Cache
{
$cacheDirectory = $this->parameterProvider->provideStringParameter(\Rector\Core\Configuration\Option::CACHE_DIR);
// ensure cache directory exists
if (!$this->smartFileSystem->exists($cacheDirectory)) {
$this->smartFileSystem->mkdir($cacheDirectory);
$cacheClass = \Rector\Caching\ValueObject\Storage\FileCacheStorage::class;
if ($this->parameterProvider->hasParameter(\Rector\Core\Configuration\Option::CACHE_CLASS)) {
$cacheClass = $this->parameterProvider->provideStringParameter(\Rector\Core\Configuration\Option::CACHE_CLASS);
}
$fileCacheStorage = new \Rector\Caching\ValueObject\Storage\FileCacheStorage($cacheDirectory, $this->smartFileSystem);
return new \Rector\Caching\Cache($fileCacheStorage);
if ($cacheClass === \Rector\Caching\ValueObject\Storage\FileCacheStorage::class) {
// ensure cache directory exists
if (!$this->smartFileSystem->exists($cacheDirectory)) {
$this->smartFileSystem->mkdir($cacheDirectory);
}
$fileCacheStorage = new \Rector\Caching\ValueObject\Storage\FileCacheStorage($cacheDirectory, $this->smartFileSystem);
return new \Rector\Caching\Cache($fileCacheStorage);
}
return new \Rector\Caching\Cache(new \Rector\Caching\ValueObject\Storage\MemoryCacheStorage());
}
}

View File

@ -0,0 +1,28 @@
<?php
declare (strict_types=1);
namespace Rector\Caching\ValueObject\Storage;
/**
* inspired by https://github.com/phpstan/phpstan-src/blob/560652088406d7461c2c4ad4897784e33f8ab312/src/Cache/CacheStorage.php
*/
interface CacheStorageInterface
{
/**
* @return mixed|null
* @param string $key
* @param string $variableKey
*/
public function load($key, $variableKey);
/**
* @param mixed $data
* @param string $key
* @param string $variableKey
*/
public function save($key, $variableKey, $data) : void;
/**
* @param string $key
*/
public function clean($key) : void;
public function clear() : void;
}

View File

@ -12,7 +12,7 @@ use RectorPrefix20210728\Symplify\SmartFileSystem\SmartFileSystem;
/**
* Inspired by https://github.com/phpstan/phpstan-src/blob/1e7ceae933f07e5a250b61ed94799e6c2ea8daa2/src/Cache/FileCacheStorage.php
*/
final class FileCacheStorage
final class FileCacheStorage implements \Rector\Caching\ValueObject\Storage\CacheStorageInterface
{
/**
* @var string
@ -28,9 +28,10 @@ final class FileCacheStorage
$this->smartFileSystem = $smartFileSystem;
}
/**
* @return mixed|null
* @param string $key
* @param string $variableKey
*/
public function load(string $key, string $variableKey)
public function load($key, $variableKey)
{
return (function (string $key, string $variableKey) {
$cacheFilePaths = $this->getCacheFilePaths($key);
@ -49,9 +50,10 @@ final class FileCacheStorage
})($key, $variableKey);
}
/**
* @param mixed $data
* @param string $key
* @param string $variableKey
*/
public function save(string $key, string $variableKey, $data) : void
public function save($key, $variableKey, $data) : void
{
$cacheFilePaths = $this->getCacheFilePaths($key);
$this->smartFileSystem->mkdir($cacheFilePaths->getFirstDirectory());
@ -75,9 +77,12 @@ final class FileCacheStorage
throw new \RectorPrefix20210728\Symplify\EasyCodingStandard\Caching\Exception\CachingException(\sprintf('Could not write data to cache file %s.', $path));
}
}
public function clean(string $cacheKey) : void
/**
* @param string $key
*/
public function clean($key) : void
{
$cacheFilePaths = $this->getCacheFilePaths($cacheKey);
$cacheFilePaths = $this->getCacheFilePaths($key);
$this->smartFileSystem->remove([$cacheFilePaths->getFirstDirectory(), $cacheFilePaths->getSecondDirectory(), $cacheFilePaths->getFilePath()]);
}
public function clear() : void

View File

@ -0,0 +1,51 @@
<?php
declare (strict_types=1);
namespace Rector\Caching\ValueObject\Storage;
use Rector\Caching\ValueObject\CacheItem;
/**
* inspired by https://github.com/phpstan/phpstan-src/blob/560652088406d7461c2c4ad4897784e33f8ab312/src/Cache/MemoryCacheStorage.php
*/
class MemoryCacheStorage implements \Rector\Caching\ValueObject\Storage\CacheStorageInterface
{
/** @var array<string, CacheItem> */
private $storage = [];
/**
* @param string $key
* @param string $variableKey
*/
public function load($key, $variableKey)
{
if (!isset($this->storage[$key])) {
return null;
}
$item = $this->storage[$key];
if (!$item->isVariableKeyValid($variableKey)) {
return null;
}
return $item->getData();
}
/**
* @param string $key
* @param string $variableKey
*/
public function save($key, $variableKey, $data) : void
{
$this->storage[$key] = new \Rector\Caching\ValueObject\CacheItem($variableKey, $data);
}
/**
* @param string $key
*/
public function clean($key) : void
{
if (!isset($this->storage[$key])) {
return;
}
unset($this->storage[$key]);
}
public function clear() : void
{
$this->storage = [];
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'a7f111e201b95271acfdd090d017e3d112c5d1dd';
public const PACKAGE_VERSION = '687a77765f975a2449ea8010192ac84e6548bc51';
/**
* @var string
*/
public const RELEASE_DATE = '2021-07-28 04:28:25';
public const RELEASE_DATE = '2021-07-28 08:53:49';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20210728\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

View File

@ -4,6 +4,8 @@ declare (strict_types=1);
namespace Rector\Core\Configuration;
use RectorPrefix20210728\JetBrains\PhpStorm\Immutable;
use Rector\Caching\ValueObject\Storage\CacheStorageInterface;
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use RectorPrefix20210728\Symplify\Skipper\ValueObject\Option as SkipperOption;
#[Immutable]
final class Option
@ -89,6 +91,13 @@ final class Option
* @var string
*/
public const CACHE_DIR = 'cache_dir';
/**
* Cache backend. Most of the time we cache in files, but in ephemeral environment (e.g. CI), a faster `MemoryCacheStorage` can be usefull.
*
* @var class-string<CacheStorageInterface>
* @internal
*/
public const CACHE_CLASS = \Rector\Caching\ValueObject\Storage\FileCacheStorage::class;
/**
* @var string
*/

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit4f76720e260d13b441cf5fb5b5f30789::getLoader();
return ComposerAutoloaderInitce07743fbc1642af6a1e16cdbe684ff5::getLoader();

View File

@ -1572,7 +1572,9 @@ return array(
'Rector\\Caching\\UnchangedFilesFilter' => $baseDir . '/packages/Caching/UnchangedFilesFilter.php',
'Rector\\Caching\\ValueObject\\CacheFilePaths' => $baseDir . '/packages/Caching/ValueObject/CacheFilePaths.php',
'Rector\\Caching\\ValueObject\\CacheItem' => $baseDir . '/packages/Caching/ValueObject/CacheItem.php',
'Rector\\Caching\\ValueObject\\Storage\\CacheStorageInterface' => $baseDir . '/packages/Caching/ValueObject/Storage/CacheStorageInterface.php',
'Rector\\Caching\\ValueObject\\Storage\\FileCacheStorage' => $baseDir . '/packages/Caching/ValueObject/Storage/FileCacheStorage.php',
'Rector\\Caching\\ValueObject\\Storage\\MemoryCacheStorage' => $baseDir . '/packages/Caching/ValueObject/Storage/MemoryCacheStorage.php',
'Rector\\CakePHP\\ImplicitNameResolver' => $vendorDir . '/rector/rector-cakephp/src/ImplicitNameResolver.php',
'Rector\\CakePHP\\Naming\\CakePHPFullyQualifiedClassNameResolver' => $vendorDir . '/rector/rector-cakephp/src/Naming/CakePHPFullyQualifiedClassNameResolver.php',
'Rector\\CakePHP\\Rector\\MethodCall\\ArrayToFluentCallRector' => $vendorDir . '/rector/rector-cakephp/src/Rector/MethodCall/ArrayToFluentCallRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit4f76720e260d13b441cf5fb5b5f30789
class ComposerAutoloaderInitce07743fbc1642af6a1e16cdbe684ff5
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit4f76720e260d13b441cf5fb5b5f30789
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit4f76720e260d13b441cf5fb5b5f30789', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitce07743fbc1642af6a1e16cdbe684ff5', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit4f76720e260d13b441cf5fb5b5f30789', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitce07743fbc1642af6a1e16cdbe684ff5', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit4f76720e260d13b441cf5fb5b5f30789::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitce07743fbc1642af6a1e16cdbe684ff5::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInit4f76720e260d13b441cf5fb5b5f30789
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit4f76720e260d13b441cf5fb5b5f30789::$files;
$includeFiles = Composer\Autoload\ComposerStaticInitce07743fbc1642af6a1e16cdbe684ff5::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire4f76720e260d13b441cf5fb5b5f30789($fileIdentifier, $file);
composerRequirece07743fbc1642af6a1e16cdbe684ff5($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire4f76720e260d13b441cf5fb5b5f30789($fileIdentifier, $file)
function composerRequirece07743fbc1642af6a1e16cdbe684ff5($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit4f76720e260d13b441cf5fb5b5f30789
class ComposerStaticInitce07743fbc1642af6a1e16cdbe684ff5
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -1927,7 +1927,9 @@ class ComposerStaticInit4f76720e260d13b441cf5fb5b5f30789
'Rector\\Caching\\UnchangedFilesFilter' => __DIR__ . '/../..' . '/packages/Caching/UnchangedFilesFilter.php',
'Rector\\Caching\\ValueObject\\CacheFilePaths' => __DIR__ . '/../..' . '/packages/Caching/ValueObject/CacheFilePaths.php',
'Rector\\Caching\\ValueObject\\CacheItem' => __DIR__ . '/../..' . '/packages/Caching/ValueObject/CacheItem.php',
'Rector\\Caching\\ValueObject\\Storage\\CacheStorageInterface' => __DIR__ . '/../..' . '/packages/Caching/ValueObject/Storage/CacheStorageInterface.php',
'Rector\\Caching\\ValueObject\\Storage\\FileCacheStorage' => __DIR__ . '/../..' . '/packages/Caching/ValueObject/Storage/FileCacheStorage.php',
'Rector\\Caching\\ValueObject\\Storage\\MemoryCacheStorage' => __DIR__ . '/../..' . '/packages/Caching/ValueObject/Storage/MemoryCacheStorage.php',
'Rector\\CakePHP\\ImplicitNameResolver' => __DIR__ . '/..' . '/rector/rector-cakephp/src/ImplicitNameResolver.php',
'Rector\\CakePHP\\Naming\\CakePHPFullyQualifiedClassNameResolver' => __DIR__ . '/..' . '/rector/rector-cakephp/src/Naming/CakePHPFullyQualifiedClassNameResolver.php',
'Rector\\CakePHP\\Rector\\MethodCall\\ArrayToFluentCallRector' => __DIR__ . '/..' . '/rector/rector-cakephp/src/Rector/MethodCall/ArrayToFluentCallRector.php',
@ -3846,9 +3848,9 @@ class ComposerStaticInit4f76720e260d13b441cf5fb5b5f30789
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit4f76720e260d13b441cf5fb5b5f30789::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit4f76720e260d13b441cf5fb5b5f30789::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit4f76720e260d13b441cf5fb5b5f30789::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitce07743fbc1642af6a1e16cdbe684ff5::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitce07743fbc1642af6a1e16cdbe684ff5::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitce07743fbc1642af6a1e16cdbe684ff5::$classMap;
}, null, ClassLoader::class);
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20210728\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit4f76720e260d13b441cf5fb5b5f30789', false) && !interface_exists('ComposerAutoloaderInit4f76720e260d13b441cf5fb5b5f30789', false) && !trait_exists('ComposerAutoloaderInit4f76720e260d13b441cf5fb5b5f30789', false)) {
spl_autoload_call('RectorPrefix20210728\ComposerAutoloaderInit4f76720e260d13b441cf5fb5b5f30789');
if (!class_exists('ComposerAutoloaderInitce07743fbc1642af6a1e16cdbe684ff5', false) && !interface_exists('ComposerAutoloaderInitce07743fbc1642af6a1e16cdbe684ff5', false) && !trait_exists('ComposerAutoloaderInitce07743fbc1642af6a1e16cdbe684ff5', false)) {
spl_autoload_call('RectorPrefix20210728\ComposerAutoloaderInitce07743fbc1642af6a1e16cdbe684ff5');
}
if (!class_exists('Doctrine\Inflector\Inflector', false) && !interface_exists('Doctrine\Inflector\Inflector', false) && !trait_exists('Doctrine\Inflector\Inflector', false)) {
spl_autoload_call('RectorPrefix20210728\Doctrine\Inflector\Inflector');
@ -3308,9 +3308,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20210728\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire4f76720e260d13b441cf5fb5b5f30789')) {
function composerRequire4f76720e260d13b441cf5fb5b5f30789() {
return \RectorPrefix20210728\composerRequire4f76720e260d13b441cf5fb5b5f30789(...func_get_args());
if (!function_exists('composerRequirece07743fbc1642af6a1e16cdbe684ff5')) {
function composerRequirece07743fbc1642af6a1e16cdbe684ff5() {
return \RectorPrefix20210728\composerRequirece07743fbc1642af6a1e16cdbe684ff5(...func_get_args());
}
}
if (!function_exists('parseArgs')) {