Updated Rector to commit 6478ec1c41

6478ec1c41 Sync FileCacheStorage with changes from phpstan-src (#498)
This commit is contained in:
Tomas Votruba 2021-07-26 13:28:02 +00:00
parent 97c6e16a85
commit 2e2725a511
6 changed files with 56 additions and 44 deletions

View File

@ -4,14 +4,13 @@ declare (strict_types=1);
namespace Rector\Caching\ValueObject\Storage;
use RectorPrefix20210726\Nette\Utils\Random;
use RectorPrefix20210726\Nette\Utils\Strings;
use Rector\Caching\ValueObject\CacheFilePaths;
use Rector\Caching\ValueObject\CacheItem;
use RectorPrefix20210726\Symplify\EasyCodingStandard\Caching\Exception\CachingException;
use PHPStan\File\FileWriter;
use RectorPrefix20210726\Symplify\SmartFileSystem\SmartFileSystem;
use RectorPrefix20210726\Symplify\EasyCodingStandard\Caching\Exception\CachingException;
/**
* Inspired by
* https://github.com/phpstan/phpstan-src/commit/4df7342f3a0aaef4bcd85456dd20ca88d38dd90d#diff-6dc14f6222bf150e6840ca44a7126653052a1cedc6a149b4e5c1e1a2c80eacdc
* Inspired by https://github.com/phpstan/phpstan-src/blob/1e7ceae933f07e5a250b61ed94799e6c2ea8daa2/src/Cache/FileCacheStorage.php
*/
final class FileCacheStorage
{
@ -29,44 +28,57 @@ final class FileCacheStorage
$this->smartFileSystem = $smartFileSystem;
}
/**
* @param string $key
* @param string $variableKey
* @return mixed|null
*/
public function load(string $key, string $variableKey)
{
$cacheFilePaths = $this->getCacheFilePaths($key);
$filePath = $cacheFilePaths->getFilePath();
if (!\is_file($filePath)) {
return null;
}
$cacheItem = (require $filePath);
if (!$cacheItem instanceof \Rector\Caching\ValueObject\CacheItem) {
return null;
}
if (!$cacheItem->isVariableKeyValid($variableKey)) {
return null;
}
return $cacheItem->getData();
return (function (string $key, string $variableKey) {
$cacheFilePaths = $this->getCacheFilePaths($key);
$filePath = $cacheFilePaths->getFilePath();
if (!\is_file($filePath)) {
return null;
}
$cacheItem = (require $filePath);
if (!$cacheItem instanceof \Rector\Caching\ValueObject\CacheItem) {
return null;
}
if (!$cacheItem->isVariableKeyValid($variableKey)) {
return null;
}
return $cacheItem->getData();
})($key, $variableKey);
}
/**
* @param string $key
* @param string $variableKey
* @param mixed $data
* @return void
*/
public function save(string $key, string $variableKey, $data) : void
{
$cacheFilePaths = $this->getCacheFilePaths($key);
$this->smartFileSystem->mkdir($cacheFilePaths->getFirstDirectory());
$this->smartFileSystem->mkdir($cacheFilePaths->getSecondDirectory());
$path = $cacheFilePaths->getFilePath();
$tmpPath = \sprintf('%s/%s.tmp', $this->directory, \RectorPrefix20210726\Nette\Utils\Random::generate());
$errorBefore = \error_get_last();
$exported = @\var_export(new \Rector\Caching\ValueObject\CacheItem($variableKey, $data), \true);
$errorAfter = \error_get_last();
if ($errorAfter !== null && $errorBefore !== $errorAfter) {
$errorMessage = \sprintf('Error occurred while saving item "%s" ("%s") to cache: "%s"', $key, $variableKey, $errorAfter['message']);
throw new \RectorPrefix20210726\Symplify\EasyCodingStandard\Caching\Exception\CachingException($errorMessage);
throw new \RectorPrefix20210726\Symplify\EasyCodingStandard\Caching\Exception\CachingException(\sprintf('Error occurred while saving item %s (%s) to cache: %s', $key, $variableKey, $errorAfter['message']));
}
// for performance reasons we don't use SmartFileSystem
\PHPStan\File\FileWriter::write($tmpPath, \sprintf("<?php declare(strict_types = 1);\n\nreturn %s;", $exported));
$renameSuccess = @\rename($tmpPath, $path);
if ($renameSuccess) {
return;
}
@\unlink($tmpPath);
if (\DIRECTORY_SEPARATOR === '/' || !\file_exists($path)) {
throw new \RectorPrefix20210726\Symplify\EasyCodingStandard\Caching\Exception\CachingException(\sprintf('Could not write data to cache file %s.', $path));
}
$variableFileContent = \sprintf("<?php declare(strict_types = 1);\n\nreturn %s;", $exported);
$this->smartFileSystem->dumpFile($tmpPath, $variableFileContent);
$this->smartFileSystem->rename($tmpPath, $cacheFilePaths->getFilePath(), \true);
$this->smartFileSystem->remove($tmpPath);
}
public function clean(string $cacheKey) : void
{
@ -80,8 +92,8 @@ final class FileCacheStorage
private function getCacheFilePaths(string $key) : \Rector\Caching\ValueObject\CacheFilePaths
{
$keyHash = \sha1($key);
$firstDirectory = \sprintf('%s/%s', $this->directory, \RectorPrefix20210726\Nette\Utils\Strings::substring($keyHash, 0, 2));
$secondDirectory = \sprintf('%s/%s', $firstDirectory, \RectorPrefix20210726\Nette\Utils\Strings::substring($keyHash, 2, 2));
$firstDirectory = \sprintf('%s/%s', $this->directory, \substr($keyHash, 0, 2));
$secondDirectory = \sprintf('%s/%s', $firstDirectory, \substr($keyHash, 2, 2));
$filePath = \sprintf('%s/%s.php', $secondDirectory, $keyHash);
return new \Rector\Caching\ValueObject\CacheFilePaths($firstDirectory, $secondDirectory, $filePath);
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'b47f2c980dac6f39c680c393489c843c3d6a5498';
public const PACKAGE_VERSION = '6478ec1c41639675a88d7056ca441d0acec2ba5e';
/**
* @var string
*/
public const RELEASE_DATE = '2021-07-26 15:03:26';
public const RELEASE_DATE = '2021-07-26 15:16:10';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20210726\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit6ca089aa39b0f9af2f43a76ffdf1918a
class ComposerAutoloaderInit0e3e1b5a39c212c3f3fdbc77395db1e9
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit6ca089aa39b0f9af2f43a76ffdf1918a
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit6ca089aa39b0f9af2f43a76ffdf1918a', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit0e3e1b5a39c212c3f3fdbc77395db1e9', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit6ca089aa39b0f9af2f43a76ffdf1918a', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit0e3e1b5a39c212c3f3fdbc77395db1e9', '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\ComposerStaticInit6ca089aa39b0f9af2f43a76ffdf1918a::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit0e3e1b5a39c212c3f3fdbc77395db1e9::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInit6ca089aa39b0f9af2f43a76ffdf1918a
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit6ca089aa39b0f9af2f43a76ffdf1918a::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit0e3e1b5a39c212c3f3fdbc77395db1e9::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire6ca089aa39b0f9af2f43a76ffdf1918a($fileIdentifier, $file);
composerRequire0e3e1b5a39c212c3f3fdbc77395db1e9($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire6ca089aa39b0f9af2f43a76ffdf1918a($fileIdentifier, $file)
function composerRequire0e3e1b5a39c212c3f3fdbc77395db1e9($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit6ca089aa39b0f9af2f43a76ffdf1918a
class ComposerStaticInit0e3e1b5a39c212c3f3fdbc77395db1e9
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -3846,9 +3846,9 @@ class ComposerStaticInit6ca089aa39b0f9af2f43a76ffdf1918a
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit6ca089aa39b0f9af2f43a76ffdf1918a::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6ca089aa39b0f9af2f43a76ffdf1918a::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6ca089aa39b0f9af2f43a76ffdf1918a::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit0e3e1b5a39c212c3f3fdbc77395db1e9::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit0e3e1b5a39c212c3f3fdbc77395db1e9::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit0e3e1b5a39c212c3f3fdbc77395db1e9::$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('RectorPrefix20210726\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit6ca089aa39b0f9af2f43a76ffdf1918a', false) && !interface_exists('ComposerAutoloaderInit6ca089aa39b0f9af2f43a76ffdf1918a', false) && !trait_exists('ComposerAutoloaderInit6ca089aa39b0f9af2f43a76ffdf1918a', false)) {
spl_autoload_call('RectorPrefix20210726\ComposerAutoloaderInit6ca089aa39b0f9af2f43a76ffdf1918a');
if (!class_exists('ComposerAutoloaderInit0e3e1b5a39c212c3f3fdbc77395db1e9', false) && !interface_exists('ComposerAutoloaderInit0e3e1b5a39c212c3f3fdbc77395db1e9', false) && !trait_exists('ComposerAutoloaderInit0e3e1b5a39c212c3f3fdbc77395db1e9', false)) {
spl_autoload_call('RectorPrefix20210726\ComposerAutoloaderInit0e3e1b5a39c212c3f3fdbc77395db1e9');
}
if (!class_exists('Doctrine\Inflector\Inflector', false) && !interface_exists('Doctrine\Inflector\Inflector', false) && !trait_exists('Doctrine\Inflector\Inflector', false)) {
spl_autoload_call('RectorPrefix20210726\Doctrine\Inflector\Inflector');
@ -3308,9 +3308,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20210726\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire6ca089aa39b0f9af2f43a76ffdf1918a')) {
function composerRequire6ca089aa39b0f9af2f43a76ffdf1918a() {
return \RectorPrefix20210726\composerRequire6ca089aa39b0f9af2f43a76ffdf1918a(...func_get_args());
if (!function_exists('composerRequire0e3e1b5a39c212c3f3fdbc77395db1e9')) {
function composerRequire0e3e1b5a39c212c3f3fdbc77395db1e9() {
return \RectorPrefix20210726\composerRequire0e3e1b5a39c212c3f3fdbc77395db1e9(...func_get_args());
}
}
if (!function_exists('parseArgs')) {