mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 14:27:14 +01:00
Updated Rector to commit 88cad6c191a1117c928e86a39875f80551308677
88cad6c191
Add moved file (#627)
This commit is contained in:
parent
e528c78dfe
commit
dfbd226240
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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__);
|
||||
|
43
src/ValueObject/Application/MovedFile.php
Normal file
43
src/ValueObject/Application/MovedFile.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\ValueObject\Application;
|
||||
|
||||
use PhpParser\Node\Stmt;
|
||||
use Rector\FileSystemRector\Contract\FileWithNodesInterface;
|
||||
final class MovedFile implements \Rector\FileSystemRector\Contract\FileWithNodesInterface
|
||||
{
|
||||
/**
|
||||
* @var \Rector\Core\ValueObject\Application\File
|
||||
*/
|
||||
private $file;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $newFilePath;
|
||||
public function __construct(\Rector\Core\ValueObject\Application\File $file, string $newFilePath)
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
}
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit9d30aab197e6b91f11e4317899373676::getLoader();
|
||||
return ComposerAutoloaderInit5ac7f6d3155d290b95745e768df725ae::getLoader();
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -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',
|
||||
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
@ -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;
|
||||
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
@ -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);
|
||||
}
|
||||
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
@ -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')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user