From dfbd2262406243e861a4e282bca1f6752566999a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 9 Aug 2021 11:34:43 +0000 Subject: [PATCH] Updated Rector to commit 88cad6c191a1117c928e86a39875f80551308677 https://github.com/rectorphp/rector-src/commit/88cad6c191a1117c928e86a39875f80551308677 Add moved file (#627) --- .../Class_/RenameSpecFileToTestFileRector.php | 7 ++- .../RemovedAndAddedFilesCollector.php | 29 +++++++++++-- .../RemovedAndAddedFilesProcessor.php | 15 +++++++ src/Application/VersionResolver.php | 4 +- src/ValueObject/Application/MovedFile.php | 43 +++++++++++++++++++ vendor/autoload.php | 2 +- vendor/composer/autoload_classmap.php | 1 + vendor/composer/autoload_real.php | 14 +++--- vendor/composer/autoload_static.php | 9 ++-- vendor/scoper-autoload.php | 10 ++--- 10 files changed, 108 insertions(+), 26 deletions(-) create mode 100644 src/ValueObject/Application/MovedFile.php diff --git a/rules/PhpSpecToPHPUnit/Rector/Class_/RenameSpecFileToTestFileRector.php b/rules/PhpSpecToPHPUnit/Rector/Class_/RenameSpecFileToTestFileRector.php index 70ee85f900e..4484766e349 100644 --- a/rules/PhpSpecToPHPUnit/Rector/Class_/RenameSpecFileToTestFileRector.php +++ b/rules/PhpSpecToPHPUnit/Rector/Class_/RenameSpecFileToTestFileRector.php @@ -7,7 +7,7 @@ use RectorPrefix20210809\Nette\Utils\Strings; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use Rector\Core\Rector\AbstractRector; -use Rector\FileSystemRector\ValueObject\AddedFileWithContent; +use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** @@ -55,10 +55,9 @@ CODE_SAMPLE if (!\RectorPrefix20210809\Nette\Utils\Strings::match($oldPathname, self::SPEC_SUFFIX_REGEX)) { return null; } - $this->removedAndAddedFilesCollector->removeFile($smartFileInfo); $newPathName = $this->createPathName($oldPathname); - $addedFileWithContent = new \Rector\FileSystemRector\ValueObject\AddedFileWithContent($newPathName, $smartFileInfo->getContents()); - $this->removedAndAddedFilesCollector->addAddedFile($addedFileWithContent); + $file = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::FILE); + $this->removedAndAddedFilesCollector->addMovedFile($file, $newPathName); return null; } private function createPathName(string $oldRealPath) : string diff --git a/src/Application/FileSystem/RemovedAndAddedFilesCollector.php b/src/Application/FileSystem/RemovedAndAddedFilesCollector.php index bc117cdbc1f..60bb97d6c01 100644 --- a/src/Application/FileSystem/RemovedAndAddedFilesCollector.php +++ b/src/Application/FileSystem/RemovedAndAddedFilesCollector.php @@ -3,6 +3,8 @@ declare (strict_types=1); namespace Rector\Core\Application\FileSystem; +use Rector\Core\ValueObject\Application\File; +use Rector\Core\ValueObject\Application\MovedFile; use Rector\FileSystemRector\Contract\AddedFileInterface; use Rector\FileSystemRector\ValueObject\AddedFileWithContent; use Rector\FileSystemRector\ValueObject\AddedFileWithNodes; @@ -17,6 +19,10 @@ final class RemovedAndAddedFilesCollector * @var AddedFileInterface[] */ private $addedFiles = []; + /** + * @var MovedFile[] + */ + private $movedFiles = []; public function removeFile(\Symplify\SmartFileSystem\SmartFileInfo $smartFileInfo) : void { $this->removedFileInfos[] = $smartFileInfo; @@ -30,9 +36,6 @@ final class RemovedAndAddedFilesCollector } public function isFileRemoved(\Symplify\SmartFileSystem\SmartFileInfo $smartFileInfo) : bool { - if ($this->removedFileInfos === []) { - return \false; - } // early assign to variable for increase performance // @see https://3v4l.org/FM3vY#focus=8.0.7 vs https://3v4l.org/JZW7b#focus=8.0.7 $pathname = $smartFileInfo->getPathname(); @@ -42,6 +45,14 @@ final class RemovedAndAddedFilesCollector } return \true; } + foreach ($this->movedFiles as $movedFile) { + $file = $movedFile->getFile(); + $fileInfo = $file->getSmartFileInfo(); + if ($fileInfo->getPathname() !== $pathname) { + continue; + } + return \true; + } return \false; } public function addAddedFile(\Rector\FileSystemRector\Contract\AddedFileInterface $addedFile) : void @@ -84,6 +95,18 @@ final class RemovedAndAddedFilesCollector public function reset() : void { $this->addedFiles = []; + $this->movedFiles = []; $this->removedFileInfos = []; } + public function addMovedFile(\Rector\Core\ValueObject\Application\File $file, string $newPathName) : void + { + $this->movedFiles[] = new \Rector\Core\ValueObject\Application\MovedFile($file, $newPathName); + } + /** + * @return MovedFile[] + */ + public function getMovedFiles() : array + { + return $this->movedFiles; + } } diff --git a/src/Application/FileSystem/RemovedAndAddedFilesProcessor.php b/src/Application/FileSystem/RemovedAndAddedFilesProcessor.php index ced0db35030..3a0338832fa 100644 --- a/src/Application/FileSystem/RemovedAndAddedFilesProcessor.php +++ b/src/Application/FileSystem/RemovedAndAddedFilesProcessor.php @@ -39,6 +39,7 @@ final class RemovedAndAddedFilesProcessor { $this->processAddedFilesWithContent($configuration); $this->processAddedFilesWithNodes($configuration); + $this->processMovedFilesWithNodes($configuration); $this->processDeletedFiles($configuration); } private function processDeletedFiles(\Rector\Core\ValueObject\Configuration $configuration) : void @@ -82,4 +83,18 @@ final class RemovedAndAddedFilesProcessor } } } + private function processMovedFilesWithNodes(\Rector\Core\ValueObject\Configuration $configuration) : void + { + foreach ($this->removedAndAddedFilesCollector->getMovedFiles() as $movedFile) { + $fileContent = $this->nodesWithFileDestinationPrinter->printNodesWithFileDestination($movedFile); + if ($configuration->isDryRun()) { + $message = \sprintf('File "%s" will be moved to "%s"', $movedFile->getFilePath(), $movedFile->getNewFilePath()); + $this->symfonyStyle->note($message); + } else { + $this->smartFileSystem->dumpFile($movedFile->getNewFilePath(), $fileContent); + $message = \sprintf('File "%s" was moved to "%s"', $movedFile->getFilePath(), $movedFile->getNewFilePath()); + $this->symfonyStyle->note($message); + } + } + } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index f7f24a02360..f8f53b00792 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -16,11 +16,11 @@ final class VersionResolver /** * @var string */ - public const PACKAGE_VERSION = '6fe42bd0b368b92a56f1a12fe5bfc06fa16bb691'; + public const PACKAGE_VERSION = '88cad6c191a1117c928e86a39875f80551308677'; /** * @var string */ - public const RELEASE_DATE = '2021-08-09 12:50:07'; + public const RELEASE_DATE = '2021-08-09 13:21:35'; public static function resolvePackageVersion() : string { $process = new \RectorPrefix20210809\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__); diff --git a/src/ValueObject/Application/MovedFile.php b/src/ValueObject/Application/MovedFile.php new file mode 100644 index 00000000000..2551a90bd3a --- /dev/null +++ b/src/ValueObject/Application/MovedFile.php @@ -0,0 +1,43 @@ +file = $file; + $this->newFilePath = $newFilePath; + } + public function getFile() : \Rector\Core\ValueObject\Application\File + { + return $this->file; + } + public function getNewFilePath() : string + { + return $this->newFilePath; + } + /** + * @return Stmt[] + */ + public function getNodes() : array + { + return $this->file->getNewStmts(); + } + public function getFilePath() : string + { + $smartFileInfo = $this->file->getSmartFileInfo(); + return $smartFileInfo->getRelativeFilePath(); + } +} diff --git a/vendor/autoload.php b/vendor/autoload.php index 0d987c213ef..e8593883b49 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit9d30aab197e6b91f11e4317899373676::getLoader(); +return ComposerAutoloaderInit5ac7f6d3155d290b95745e768df725ae::getLoader(); diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 969f2bfeb96..bcd5e88c690 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -1914,6 +1914,7 @@ return array( 'Rector\\Core\\ValueObjectFactory\\Application\\FileFactory' => $baseDir . '/src/ValueObjectFactory/Application/FileFactory.php', 'Rector\\Core\\ValueObjectFactory\\ProcessResultFactory' => $baseDir . '/src/ValueObjectFactory/ProcessResultFactory.php', 'Rector\\Core\\ValueObject\\Application\\File' => $baseDir . '/src/ValueObject/Application/File.php', + 'Rector\\Core\\ValueObject\\Application\\MovedFile' => $baseDir . '/src/ValueObject/Application/MovedFile.php', 'Rector\\Core\\ValueObject\\Application\\RectorError' => $baseDir . '/src/ValueObject/Application/RectorError.php', 'Rector\\Core\\ValueObject\\Bootstrap\\BootstrapConfigs' => $baseDir . '/src/ValueObject/Bootstrap/BootstrapConfigs.php', 'Rector\\Core\\ValueObject\\Configuration' => $baseDir . '/src/ValueObject/Configuration.php', diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 229b7b44710..2f6eab2394f 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit9d30aab197e6b91f11e4317899373676 +class ComposerAutoloaderInit5ac7f6d3155d290b95745e768df725ae { private static $loader; @@ -22,15 +22,15 @@ class ComposerAutoloaderInit9d30aab197e6b91f11e4317899373676 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit9d30aab197e6b91f11e4317899373676', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit5ac7f6d3155d290b95745e768df725ae', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); - spl_autoload_unregister(array('ComposerAutoloaderInit9d30aab197e6b91f11e4317899373676', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit5ac7f6d3155d290b95745e768df725ae', '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\ComposerStaticInit9d30aab197e6b91f11e4317899373676::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit5ac7f6d3155d290b95745e768df725ae::getInitializer($loader)); } else { $classMap = require __DIR__ . '/autoload_classmap.php'; if ($classMap) { @@ -42,19 +42,19 @@ class ComposerAutoloaderInit9d30aab197e6b91f11e4317899373676 $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInit9d30aab197e6b91f11e4317899373676::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit5ac7f6d3155d290b95745e768df725ae::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire9d30aab197e6b91f11e4317899373676($fileIdentifier, $file); + composerRequire5ac7f6d3155d290b95745e768df725ae($fileIdentifier, $file); } return $loader; } } -function composerRequire9d30aab197e6b91f11e4317899373676($fileIdentifier, $file) +function composerRequire5ac7f6d3155d290b95745e768df725ae($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index b2b5de4c9b3..a1a3126ce34 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit9d30aab197e6b91f11e4317899373676 +class ComposerStaticInit5ac7f6d3155d290b95745e768df725ae { public static $files = array ( 'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php', @@ -2274,6 +2274,7 @@ class ComposerStaticInit9d30aab197e6b91f11e4317899373676 'Rector\\Core\\ValueObjectFactory\\Application\\FileFactory' => __DIR__ . '/../..' . '/src/ValueObjectFactory/Application/FileFactory.php', 'Rector\\Core\\ValueObjectFactory\\ProcessResultFactory' => __DIR__ . '/../..' . '/src/ValueObjectFactory/ProcessResultFactory.php', 'Rector\\Core\\ValueObject\\Application\\File' => __DIR__ . '/../..' . '/src/ValueObject/Application/File.php', + 'Rector\\Core\\ValueObject\\Application\\MovedFile' => __DIR__ . '/../..' . '/src/ValueObject/Application/MovedFile.php', 'Rector\\Core\\ValueObject\\Application\\RectorError' => __DIR__ . '/../..' . '/src/ValueObject/Application/RectorError.php', 'Rector\\Core\\ValueObject\\Bootstrap\\BootstrapConfigs' => __DIR__ . '/../..' . '/src/ValueObject/Bootstrap/BootstrapConfigs.php', 'Rector\\Core\\ValueObject\\Configuration' => __DIR__ . '/../..' . '/src/ValueObject/Configuration.php', @@ -3847,9 +3848,9 @@ class ComposerStaticInit9d30aab197e6b91f11e4317899373676 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit9d30aab197e6b91f11e4317899373676::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit9d30aab197e6b91f11e4317899373676::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit9d30aab197e6b91f11e4317899373676::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit5ac7f6d3155d290b95745e768df725ae::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit5ac7f6d3155d290b95745e768df725ae::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit5ac7f6d3155d290b95745e768df725ae::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/scoper-autoload.php b/vendor/scoper-autoload.php index aef70bed5ac..8931da06920 100644 --- a/vendor/scoper-autoload.php +++ b/vendor/scoper-autoload.php @@ -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('RectorPrefix20210809\AutoloadIncluder'); } -if (!class_exists('ComposerAutoloaderInit9d30aab197e6b91f11e4317899373676', false) && !interface_exists('ComposerAutoloaderInit9d30aab197e6b91f11e4317899373676', false) && !trait_exists('ComposerAutoloaderInit9d30aab197e6b91f11e4317899373676', false)) { - spl_autoload_call('RectorPrefix20210809\ComposerAutoloaderInit9d30aab197e6b91f11e4317899373676'); +if (!class_exists('ComposerAutoloaderInit5ac7f6d3155d290b95745e768df725ae', false) && !interface_exists('ComposerAutoloaderInit5ac7f6d3155d290b95745e768df725ae', false) && !trait_exists('ComposerAutoloaderInit5ac7f6d3155d290b95745e768df725ae', false)) { + spl_autoload_call('RectorPrefix20210809\ComposerAutoloaderInit5ac7f6d3155d290b95745e768df725ae'); } if (!class_exists('AjaxLogin', false) && !interface_exists('AjaxLogin', false) && !trait_exists('AjaxLogin', false)) { spl_autoload_call('RectorPrefix20210809\AjaxLogin'); @@ -3305,9 +3305,9 @@ if (!function_exists('print_node')) { return \RectorPrefix20210809\print_node(...func_get_args()); } } -if (!function_exists('composerRequire9d30aab197e6b91f11e4317899373676')) { - function composerRequire9d30aab197e6b91f11e4317899373676() { - return \RectorPrefix20210809\composerRequire9d30aab197e6b91f11e4317899373676(...func_get_args()); +if (!function_exists('composerRequire5ac7f6d3155d290b95745e768df725ae')) { + function composerRequire5ac7f6d3155d290b95745e768df725ae() { + return \RectorPrefix20210809\composerRequire5ac7f6d3155d290b95745e768df725ae(...func_get_args()); } } if (!function_exists('parseArgs')) {