Updated Rector to commit 9614997c78

9614997c78 [Parallel] Add SerializableInterface to File, RectorError and FileDiff value objects (#1178)
This commit is contained in:
Tomas Votruba 2021-11-07 14:41:05 +00:00
parent 4a6ab99856
commit 545879c4de
17 changed files with 150 additions and 59 deletions

View File

@ -39,7 +39,7 @@ final class RectorChangeCollector
if (!$currentRector instanceof \Rector\Core\Contract\Rector\RectorInterface) {
return;
}
$rectorWithLineChange = new \Rector\ChangesReporting\ValueObject\RectorWithLineChange($currentRector, $node->getLine());
$rectorWithLineChange = new \Rector\ChangesReporting\ValueObject\RectorWithLineChange(\get_class($currentRector), $node->getLine());
$file->addRectorClassWithLine($rectorWithLineChange);
}
}

View File

@ -4,30 +4,59 @@ declare (strict_types=1);
namespace Rector\ChangesReporting\ValueObject;
use Rector\Core\Contract\Rector\RectorInterface;
final class RectorWithLineChange
use Rector\Parallel\Contract\SerializableInterface;
final class RectorWithLineChange implements \Rector\Parallel\Contract\SerializableInterface
{
/**
* @var \Rector\Core\Contract\Rector\RectorInterface
* @var string
*/
private $rector;
private const KEY_RECTOR_CLASS = 'rector_class';
/**
* @var string
*/
private const KEY_LINE = 'line';
/**
* @var class-string<RectorInterface>
*/
private $rectorClass;
/**
* @var int
*/
private $line;
public function __construct(\Rector\Core\Contract\Rector\RectorInterface $rector, int $line)
/**
* @param \Rector\Core\Contract\Rector\RectorInterface|string $rectorClass
*/
public function __construct($rectorClass, int $line)
{
$this->rector = $rector;
$this->line = $line;
if ($rectorClass instanceof \Rector\Core\Contract\Rector\RectorInterface) {
$rectorClass = \get_class($rectorClass);
}
$this->rectorClass = $rectorClass;
}
/**
* @return class-string<RectorInterface>
*/
public function getRectorClass() : string
{
return \get_class($this->rector);
return $this->rectorClass;
}
public function getLine() : int
{
return $this->line;
}
/**
* @param array<string, mixed> $json
*/
public static function decode($json) : \Rector\Parallel\Contract\SerializableInterface
{
return new self($json[self::KEY_RECTOR_CLASS], $json[self::KEY_LINE]);
}
/**
* @return array<string, mixed>
*/
public function jsonSerialize() : array
{
return [self::KEY_RECTOR_CLASS => $this->rectorClass, self::KEY_LINE => $this->line];
}
}

View File

@ -20,6 +20,6 @@ final class ErrorFactory
public function createAutoloadError(\PHPStan\AnalysedCodeException $analysedCodeException, \Symplify\SmartFileSystem\SmartFileInfo $smartFileInfo) : \Rector\Core\ValueObject\Application\RectorError
{
$message = $this->exceptionCorrector->getAutoloadExceptionMessageAndAddLocation($analysedCodeException);
return new \Rector\Core\ValueObject\Application\RectorError($message, $smartFileInfo);
return new \Rector\Core\ValueObject\Application\RectorError($message, $smartFileInfo->getRelativeFilePathFromCwd());
}
}

View File

@ -25,6 +25,6 @@ final class FileDiffFactory
public function createFileDiff(\Rector\Core\ValueObject\Application\File $file, string $oldContent, string $newContent) : \Rector\Core\ValueObject\Reporting\FileDiff
{
// always keep the most recent diff
return new \Rector\Core\ValueObject\Reporting\FileDiff($file->getSmartFileInfo(), $this->defaultDiffer->diff($oldContent, $newContent), $this->consoleDiffer->diff($oldContent, $newContent), $file->getRectorWithLineChanges());
return new \Rector\Core\ValueObject\Reporting\FileDiff($file->getRelativeFilePath(), $this->defaultDiffer->diff($oldContent, $newContent), $this->consoleDiffer->diff($oldContent, $newContent), $file->getRectorWithLineChanges());
}
}

View File

@ -0,0 +1,13 @@
<?php
declare (strict_types=1);
namespace Rector\Parallel\Contract;
use JsonSerializable;
interface SerializableInterface extends \JsonSerializable
{
/**
* @param array<string, mixed> $json
*/
public static function decode($json) : self;
}

View File

@ -156,7 +156,7 @@ final class PhpFileProcessor implements \Rector\Core\Contract\Processor\FileProc
if ($this->symfonyStyle->isVerbose() || \Rector\Testing\PHPUnit\StaticPHPUnitEnvironment::isPHPUnitRun()) {
throw $throwable;
}
$rectorError = new \Rector\Core\ValueObject\Application\RectorError($throwable->getMessage(), $file->getSmartFileInfo(), $throwable->getLine());
$rectorError = new \Rector\Core\ValueObject\Application\RectorError($throwable->getMessage(), $file->getRelativeFilePath(), $throwable->getLine());
$file->addRectorError($rectorError);
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'cb54cf0e97715964e31009bb41a04480a218d80f';
public const PACKAGE_VERSION = '9614997c78837ffe3755eb2584473213a290c8ed';
/**
* @var string
*/
public const RELEASE_DATE = '2021-11-07 13:25:05';
public const RELEASE_DATE = '2021-11-07 15:26:25';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20211107\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

View File

@ -264,7 +264,7 @@ abstract class AbstractRector extends \PhpParser\NodeVisitorAbstract implements
}
// changed!
if ($this->changedNodeAnalyzer->hasNodeChanged($originalNode, $node)) {
$rectorWithLineChange = new \Rector\ChangesReporting\ValueObject\RectorWithLineChange($this, $originalNode->getLine());
$rectorWithLineChange = new \Rector\ChangesReporting\ValueObject\RectorWithLineChange(\get_class($this), $originalNode->getLine());
$this->file->addRectorClassWithLine($rectorWithLineChange);
// update parents relations - must run before connectParentNodes()
$this->mirrorAttributes($originalAttributes, $node);

View File

@ -171,4 +171,8 @@ final class File
{
return $this->rectorErrors;
}
public function getRelativeFilePath() : string
{
return $this->smartFileInfo->getRelativeFilePathFromCwd();
}
}

View File

@ -3,39 +3,39 @@
declare (strict_types=1);
namespace Rector\Core\ValueObject\Application;
use Symplify\SmartFileSystem\SmartFileInfo;
final class RectorError
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Parallel\Contract\SerializableInterface;
final class RectorError implements \Rector\Parallel\Contract\SerializableInterface
{
/**
* @var string
*/
private $message;
/**
* @var \Symplify\SmartFileSystem\SmartFileInfo
* @var string
*/
private $fileInfo;
private $relativeFilePath;
/**
* @var int|null
*/
private $line;
/**
* @var string|null
* @var class-string<\Rector\Core\Contract\Rector\RectorInterface>|null
*/
private $rectorClass;
public function __construct(string $message, \Symplify\SmartFileSystem\SmartFileInfo $fileInfo, ?int $line = null, ?string $rectorClass = null)
/**
* @param class-string<RectorInterface>|null $rectorClass
*/
public function __construct(string $message, string $relativeFilePath, ?int $line = null, ?string $rectorClass = null)
{
$this->message = $message;
$this->fileInfo = $fileInfo;
$this->relativeFilePath = $relativeFilePath;
$this->line = $line;
$this->rectorClass = $rectorClass;
}
public function getRelativeFilePath() : string
{
return $this->fileInfo->getRelativeFilePathFromCwd();
}
public function getFileInfo() : \Symplify\SmartFileSystem\SmartFileInfo
{
return $this->fileInfo;
return $this->relativeFilePath;
}
public function getMessage() : string
{
@ -45,8 +45,25 @@ final class RectorError
{
return $this->line;
}
/**
* @return class-string<RectorInterface>|null
*/
public function getRectorClass() : ?string
{
return $this->rectorClass;
}
/**
* @param array<string, mixed> $json
*/
public static function decode($json) : \Rector\Parallel\Contract\SerializableInterface
{
return new self($json['message'], $json['relative_file_path'], $json['line'], $json['rector_class']);
}
/**
* @return array<string, mixed>
*/
public function jsonSerialize() : array
{
return ['message' => $this->message, 'relative_file_path' => $this->relativeFilePath, 'line' => $this->line, 'rector_class' => $this->rectorClass];
}
}

View File

@ -83,7 +83,7 @@ final class ProcessResult
{
$fileInfos = [];
foreach ($this->fileDiffs as $fileDiff) {
$fileInfos[] = $fileDiff->getFileInfo();
$fileInfos[] = new \Symplify\SmartFileSystem\SmartFileInfo($fileDiff->getRelativeFilePath());
}
return \array_unique($fileInfos);
}

View File

@ -6,8 +6,8 @@ namespace Rector\Core\ValueObject\Reporting;
use RectorPrefix20211107\Nette\Utils\Strings;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Core\Contract\Rector\RectorInterface;
use Symplify\SmartFileSystem\SmartFileInfo;
final class FileDiff
use Rector\Parallel\Contract\SerializableInterface;
final class FileDiff implements \Rector\Parallel\Contract\SerializableInterface
{
/**
* @var string
@ -19,9 +19,25 @@ final class FileDiff
*/
private const FIRST_LINE_KEY = 'first_line';
/**
* @var \Symplify\SmartFileSystem\SmartFileInfo
* @var string
*/
private $smartFileInfo;
private const KEY_RELATIVE_FILE_PATH = 'relative_file_path';
/**
* @var string
*/
private const KEY_DIFF = 'diff';
/**
* @var string
*/
private const KEY_DIFF_CONSOLE_FORMATTED = 'diff_console_formatted';
/**
* @var string
*/
private const KEY_RECTORS_WITH_LINE_CHANGES = 'rectors_with_line_changes';
/**
* @var string
*/
private $relativeFilePath;
/**
* @var string
*/
@ -33,16 +49,16 @@ final class FileDiff
/**
* @var \Rector\ChangesReporting\ValueObject\RectorWithLineChange[]
*/
private $rectorWithLineChanges = [];
private $rectorsWithLineChanges = [];
/**
* @param RectorWithLineChange[] $rectorWithLineChanges
* @param RectorWithLineChange[] $rectorsWithLineChanges
*/
public function __construct(\Symplify\SmartFileSystem\SmartFileInfo $smartFileInfo, string $diff, string $diffConsoleFormatted, array $rectorWithLineChanges = [])
public function __construct(string $relativeFilePath, string $diff, string $diffConsoleFormatted, array $rectorsWithLineChanges = [])
{
$this->smartFileInfo = $smartFileInfo;
$this->relativeFilePath = $relativeFilePath;
$this->diff = $diff;
$this->diffConsoleFormatted = $diffConsoleFormatted;
$this->rectorWithLineChanges = $rectorWithLineChanges;
$this->rectorsWithLineChanges = $rectorsWithLineChanges;
}
public function getDiff() : string
{
@ -54,18 +70,14 @@ final class FileDiff
}
public function getRelativeFilePath() : string
{
return $this->smartFileInfo->getRelativeFilePath();
}
public function getFileInfo() : \Symplify\SmartFileSystem\SmartFileInfo
{
return $this->smartFileInfo;
return $this->relativeFilePath;
}
/**
* @return RectorWithLineChange[]
*/
public function getRectorChanges() : array
{
return $this->rectorWithLineChanges;
return $this->rectorsWithLineChanges;
}
/**
* @return array<class-string<RectorInterface>>
@ -73,7 +85,7 @@ final class FileDiff
public function getRectorClasses() : array
{
$rectorClasses = [];
foreach ($this->rectorWithLineChanges as $rectorWithLineChange) {
foreach ($this->rectorsWithLineChanges as $rectorWithLineChange) {
$rectorClasses[] = $rectorWithLineChange->getRectorClass();
}
return $this->sortClasses($rectorClasses);
@ -87,6 +99,20 @@ final class FileDiff
}
return (int) $match[self::FIRST_LINE_KEY] - 1;
}
/**
* @return array<string, mixed>
*/
public function jsonSerialize() : array
{
return [self::KEY_RELATIVE_FILE_PATH => $this->relativeFilePath, self::KEY_DIFF => $this->diff, self::KEY_DIFF_CONSOLE_FORMATTED => $this->diffConsoleFormatted, self::KEY_RECTORS_WITH_LINE_CHANGES => $this->rectorsWithLineChanges];
}
/**
* @param array<string, mixed> $json
*/
public static function decode($json) : \Rector\Parallel\Contract\SerializableInterface
{
return new self($json[self::KEY_RELATIVE_FILE_PATH], $json[self::KEY_DIFF], $json[self::KEY_DIFF_CONSOLE_FORMATTED], $json[self::KEY_RECTORS_WITH_LINE_CHANGES]);
}
/**
* @template TType as object
* @param array<class-string<TType>> $rectorClasses

2
vendor/autoload.php vendored
View File

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

View File

@ -2327,6 +2327,7 @@ return array(
'Rector\\PSR4\\NodeManipulator\\NamespaceManipulator' => $baseDir . '/rules/PSR4/NodeManipulator/NamespaceManipulator.php',
'Rector\\PSR4\\Rector\\FileWithoutNamespace\\NormalizeNamespaceByPSR4ComposerAutoloadRector' => $baseDir . '/rules/PSR4/Rector/FileWithoutNamespace/NormalizeNamespaceByPSR4ComposerAutoloadRector.php',
'Rector\\PSR4\\Rector\\Namespace_\\MultipleClassFileToPsr4ClassesRector' => $baseDir . '/rules/PSR4/Rector/Namespace_/MultipleClassFileToPsr4ClassesRector.php',
'Rector\\Parallel\\Contract\\SerializableInterface' => $baseDir . '/packages/Parallel/Contract/SerializableInterface.php',
'Rector\\Php52\\Rector\\Property\\VarToPublicPropertyRector' => $baseDir . '/rules/Php52/Rector/Property/VarToPublicPropertyRector.php',
'Rector\\Php52\\Rector\\Switch_\\ContinueToBreakInSwitchRector' => $baseDir . '/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php',
'Rector\\Php53\\Rector\\FuncCall\\DirNameFileConstantToDirConstantRector' => $baseDir . '/rules/Php53/Rector/FuncCall/DirNameFileConstantToDirConstantRector.php',

View File

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

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit0fac44200767cb1f5ae904339f24171b
class ComposerStaticInit3bac50292a314eea858d900666da55de
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -2657,6 +2657,7 @@ class ComposerStaticInit0fac44200767cb1f5ae904339f24171b
'Rector\\PSR4\\NodeManipulator\\NamespaceManipulator' => __DIR__ . '/../..' . '/rules/PSR4/NodeManipulator/NamespaceManipulator.php',
'Rector\\PSR4\\Rector\\FileWithoutNamespace\\NormalizeNamespaceByPSR4ComposerAutoloadRector' => __DIR__ . '/../..' . '/rules/PSR4/Rector/FileWithoutNamespace/NormalizeNamespaceByPSR4ComposerAutoloadRector.php',
'Rector\\PSR4\\Rector\\Namespace_\\MultipleClassFileToPsr4ClassesRector' => __DIR__ . '/../..' . '/rules/PSR4/Rector/Namespace_/MultipleClassFileToPsr4ClassesRector.php',
'Rector\\Parallel\\Contract\\SerializableInterface' => __DIR__ . '/../..' . '/packages/Parallel/Contract/SerializableInterface.php',
'Rector\\Php52\\Rector\\Property\\VarToPublicPropertyRector' => __DIR__ . '/../..' . '/rules/Php52/Rector/Property/VarToPublicPropertyRector.php',
'Rector\\Php52\\Rector\\Switch_\\ContinueToBreakInSwitchRector' => __DIR__ . '/../..' . '/rules/Php52/Rector/Switch_/ContinueToBreakInSwitchRector.php',
'Rector\\Php53\\Rector\\FuncCall\\DirNameFileConstantToDirConstantRector' => __DIR__ . '/../..' . '/rules/Php53/Rector/FuncCall/DirNameFileConstantToDirConstantRector.php',
@ -3522,9 +3523,9 @@ class ComposerStaticInit0fac44200767cb1f5ae904339f24171b
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit0fac44200767cb1f5ae904339f24171b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit0fac44200767cb1f5ae904339f24171b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit0fac44200767cb1f5ae904339f24171b::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit3bac50292a314eea858d900666da55de::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit3bac50292a314eea858d900666da55de::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit3bac50292a314eea858d900666da55de::$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('RectorPrefix20211107\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit0fac44200767cb1f5ae904339f24171b', false) && !interface_exists('ComposerAutoloaderInit0fac44200767cb1f5ae904339f24171b', false) && !trait_exists('ComposerAutoloaderInit0fac44200767cb1f5ae904339f24171b', false)) {
spl_autoload_call('RectorPrefix20211107\ComposerAutoloaderInit0fac44200767cb1f5ae904339f24171b');
if (!class_exists('ComposerAutoloaderInit3bac50292a314eea858d900666da55de', false) && !interface_exists('ComposerAutoloaderInit3bac50292a314eea858d900666da55de', false) && !trait_exists('ComposerAutoloaderInit3bac50292a314eea858d900666da55de', false)) {
spl_autoload_call('RectorPrefix20211107\ComposerAutoloaderInit3bac50292a314eea858d900666da55de');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20211107\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -3306,9 +3306,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20211107\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire0fac44200767cb1f5ae904339f24171b')) {
function composerRequire0fac44200767cb1f5ae904339f24171b() {
return \RectorPrefix20211107\composerRequire0fac44200767cb1f5ae904339f24171b(...func_get_args());
if (!function_exists('composerRequire3bac50292a314eea858d900666da55de')) {
function composerRequire3bac50292a314eea858d900666da55de() {
return \RectorPrefix20211107\composerRequire3bac50292a314eea858d900666da55de(...func_get_args());
}
}
if (!function_exists('parseArgs')) {