mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 17:00:51 +00:00
Updated Rector to commit 46d2aacd80260f0d6ff7ed0454100be3ed279b63
46d2aacd80
[Core] Ensure define before refactor() called to avoid changed during refactor (#4031)
This commit is contained in:
parent
a0204cf9f1
commit
5e8e8dbc29
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'b37e2733e1c393bc802d0c378abfa3f3f4d87068';
|
||||
public const PACKAGE_VERSION = '46d2aacd80260f0d6ff7ed0454100be3ed279b63';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-05-30 13:26:20';
|
||||
public const RELEASE_DATE = '2023-05-30 13:33:00';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -229,6 +229,8 @@ CODE_SAMPLE;
|
|||
$startTime = \microtime(\true);
|
||||
$previousMemory = \memory_get_peak_usage(\true);
|
||||
}
|
||||
// ensure origNode pulled before refactor to avoid changed during refactor, ref https://3v4l.org/YMEGN
|
||||
$originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE);
|
||||
$refactoredNode = $this->refactor($node);
|
||||
if ($isDebug) {
|
||||
$this->printConsumptions($startTime, $previousMemory);
|
||||
|
@ -245,7 +247,6 @@ CODE_SAMPLE;
|
|||
$errorMessage = \sprintf(self::EMPTY_NODE_ARRAY_MESSAGE, static::class);
|
||||
throw new ShouldNotHappenException($errorMessage);
|
||||
}
|
||||
$originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE);
|
||||
return $this->postRefactorProcess($originalNode, $node, $refactoredNode);
|
||||
}
|
||||
/**
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit5851144dc93b4c94b180537620fb3d51::getLoader();
|
||||
return ComposerAutoloaderInit36d1c94a3da985f9baa68f30f4d803cc::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -1699,7 +1699,6 @@ return array(
|
|||
'Rector\\Doctrine\\ValueObject\\ArgName' => $vendorDir . '/rector/rector-doctrine/src/ValueObject/ArgName.php',
|
||||
'Rector\\Doctrine\\ValueObject\\AssignToPropertyFetch' => $vendorDir . '/rector/rector-doctrine/src/ValueObject/AssignToPropertyFetch.php',
|
||||
'Rector\\Doctrine\\ValueObject\\DefaultAnnotationArgValue' => $vendorDir . '/rector/rector-doctrine/src/ValueObject/DefaultAnnotationArgValue.php',
|
||||
'Rector\\DowngradePhp53\\Rector\\Dir\\DirConstToFileConstRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp53/Rector/Dir/DirConstToFileConstRector.php',
|
||||
'Rector\\DowngradePhp54\\Rector\\Array_\\ShortArrayToLongArrayRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp54/Rector/Array_/ShortArrayToLongArrayRector.php',
|
||||
'Rector\\DowngradePhp54\\Rector\\Closure\\DowngradeStaticClosureRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp54/Rector/Closure/DowngradeStaticClosureRector.php',
|
||||
'Rector\\DowngradePhp54\\Rector\\Closure\\DowngradeThisInClosureRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp54/Rector/Closure/DowngradeThisInClosureRector.php',
|
||||
|
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit5851144dc93b4c94b180537620fb3d51
|
||||
class ComposerAutoloaderInit36d1c94a3da985f9baa68f30f4d803cc
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit5851144dc93b4c94b180537620fb3d51
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit5851144dc93b4c94b180537620fb3d51', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit36d1c94a3da985f9baa68f30f4d803cc', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit5851144dc93b4c94b180537620fb3d51', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit36d1c94a3da985f9baa68f30f4d803cc', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit5851144dc93b4c94b180537620fb3d51::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit36d1c94a3da985f9baa68f30f4d803cc::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit5851144dc93b4c94b180537620fb3d51::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit36d1c94a3da985f9baa68f30f4d803cc::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit5851144dc93b4c94b180537620fb3d51
|
||||
class ComposerStaticInit36d1c94a3da985f9baa68f30f4d803cc
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -1941,7 +1941,6 @@ class ComposerStaticInit5851144dc93b4c94b180537620fb3d51
|
|||
'Rector\\Doctrine\\ValueObject\\ArgName' => __DIR__ . '/..' . '/rector/rector-doctrine/src/ValueObject/ArgName.php',
|
||||
'Rector\\Doctrine\\ValueObject\\AssignToPropertyFetch' => __DIR__ . '/..' . '/rector/rector-doctrine/src/ValueObject/AssignToPropertyFetch.php',
|
||||
'Rector\\Doctrine\\ValueObject\\DefaultAnnotationArgValue' => __DIR__ . '/..' . '/rector/rector-doctrine/src/ValueObject/DefaultAnnotationArgValue.php',
|
||||
'Rector\\DowngradePhp53\\Rector\\Dir\\DirConstToFileConstRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp53/Rector/Dir/DirConstToFileConstRector.php',
|
||||
'Rector\\DowngradePhp54\\Rector\\Array_\\ShortArrayToLongArrayRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp54/Rector/Array_/ShortArrayToLongArrayRector.php',
|
||||
'Rector\\DowngradePhp54\\Rector\\Closure\\DowngradeStaticClosureRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp54/Rector/Closure/DowngradeStaticClosureRector.php',
|
||||
'Rector\\DowngradePhp54\\Rector\\Closure\\DowngradeThisInClosureRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp54/Rector/Closure/DowngradeThisInClosureRector.php',
|
||||
|
@ -3079,9 +3078,9 @@ class ComposerStaticInit5851144dc93b4c94b180537620fb3d51
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit5851144dc93b4c94b180537620fb3d51::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit5851144dc93b4c94b180537620fb3d51::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit5851144dc93b4c94b180537620fb3d51::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit36d1c94a3da985f9baa68f30f4d803cc::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit36d1c94a3da985f9baa68f30f4d803cc::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit36d1c94a3da985f9baa68f30f4d803cc::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
|
@ -1920,12 +1920,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
|
||||
"reference": "150dee55ead1c6f29d2718ce6d5b0c07bb88ae31"
|
||||
"reference": "9dbce935508b6e28618d3185cb3ed2dfd3df2f17"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/150dee55ead1c6f29d2718ce6d5b0c07bb88ae31",
|
||||
"reference": "150dee55ead1c6f29d2718ce6d5b0c07bb88ae31",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/9dbce935508b6e28618d3185cb3ed2dfd3df2f17",
|
||||
"reference": "9dbce935508b6e28618d3185cb3ed2dfd3df2f17",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1949,7 +1949,7 @@
|
|||
"tomasvotruba\/type-coverage": "^0.0.9",
|
||||
"tomasvotruba\/unused-public": "^0.0.34"
|
||||
},
|
||||
"time": "2023-05-30T10:27:45+00:00",
|
||||
"time": "2023-05-30T13:32:04+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
|
@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
|
|||
*/
|
||||
final class GeneratedConfig
|
||||
{
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 7f0656f'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 150dee5'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main e276dee'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 2348d4f'));
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 7f0656f'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9dbce93'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main e276dee'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 2348d4f'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202305;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\DowngradePhp53\Rector\Dir\DirConstToFileConstRector;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->phpVersion(PhpVersion::PHP_52);
|
||||
$rectorConfig->rule(DirConstToFileConstRector::class);
|
||||
};
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202305;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Set\ValueObject\DowngradeLevelSetList;
|
||||
use Rector\Set\ValueObject\DowngradeSetList;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_53, DowngradeSetList::PHP_53]);
|
||||
};
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\DowngradePhp53\Rector\Dir;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Scalar\MagicConst\Dir;
|
||||
use PhpParser\Node\Scalar\MagicConst\File;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://github.com/nikic/PHP-Backporter/blob/master/lib/PHPBackporter/Converter/Dir.php
|
||||
*
|
||||
* @see \Rector\Tests\DowngradePhp53\Rector\Dir\DirConstToFileConstRector\DirConstToFileConstRectorTest
|
||||
*/
|
||||
final class DirConstToFileConstRector extends AbstractRector
|
||||
{
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Refactor __DIR__ to dirname(__FILE__)', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
return dirname(__FILE__);
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Dir::class];
|
||||
}
|
||||
/**
|
||||
* @param Dir $node
|
||||
*/
|
||||
public function refactor(Node $node) : FuncCall
|
||||
{
|
||||
return $this->nodeFactory->createFuncCall('dirname', [new File()]);
|
||||
}
|
||||
}
|
|
@ -12,7 +12,6 @@ use PhpParser\Node\Stmt\Expression;
|
|||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Naming\Naming\VariableNaming;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PostRector\Collector\NodesToAddCollector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
|
@ -27,15 +26,9 @@ final class DowngradeMethodCallOnCloneRector extends AbstractRector
|
|||
* @var \Rector\Naming\Naming\VariableNaming
|
||||
*/
|
||||
private $variableNaming;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PostRector\Collector\NodesToAddCollector
|
||||
*/
|
||||
private $nodesToAddCollector;
|
||||
public function __construct(VariableNaming $variableNaming, NodesToAddCollector $nodesToAddCollector)
|
||||
public function __construct(VariableNaming $variableNaming)
|
||||
{
|
||||
$this->variableNaming = $variableNaming;
|
||||
$this->nodesToAddCollector = $nodesToAddCollector;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
|
@ -53,36 +46,26 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [MethodCall::class];
|
||||
return [Expression::class];
|
||||
}
|
||||
/**
|
||||
* @param MethodCall $node
|
||||
* @param Expression $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?MethodCall
|
||||
public function refactor(Node $node)
|
||||
{
|
||||
$isFoundCloneInAssign = \false;
|
||||
if (!$node->var instanceof Clone_) {
|
||||
if (!$node->var instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
$isFoundCloneInAssign = (bool) $this->betterNodeFinder->findFirstInstanceOf($node->var->expr, Clone_::class);
|
||||
if (!$isFoundCloneInAssign) {
|
||||
return null;
|
||||
}
|
||||
if (!$node->expr instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if ($isFoundCloneInAssign) {
|
||||
/** @var Assign $assign */
|
||||
$assign = $node->var;
|
||||
$variable = $assign->var;
|
||||
} else {
|
||||
$scope = $node->getAttribute(AttributeKey::SCOPE);
|
||||
$newVariableName = $this->variableNaming->createCountedValueName('object', $scope);
|
||||
$variable = new Variable($newVariableName);
|
||||
$assign = new Assign($variable, $node->var);
|
||||
$methodCall = $node->expr;
|
||||
if (!$methodCall->var instanceof Clone_) {
|
||||
return null;
|
||||
}
|
||||
$this->nodesToAddCollector->addNodeBeforeNode(new Expression($assign), $node);
|
||||
$node->var = $variable;
|
||||
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
|
||||
return $node;
|
||||
$clone = $methodCall->var;
|
||||
$scope = $node->getAttribute(AttributeKey::SCOPE);
|
||||
$newVariableName = $this->variableNaming->createCountedValueName('object', $scope);
|
||||
$variable = new Variable($newVariableName);
|
||||
$assign = new Assign($variable, $clone);
|
||||
$variableMethodCall = new MethodCall($variable, $methodCall->name);
|
||||
return [new Expression($assign), new Expression($variableMethodCall)];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,8 +53,4 @@ final class DowngradeLevelSetList implements SetListInterface
|
|||
* @var string
|
||||
*/
|
||||
public const DOWN_TO_PHP_53 = __DIR__ . '/../../../config/set/level/down-to-php53.php';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const DOWN_TO_PHP_52 = __DIR__ . '/../../../config/set/level/down-to-php52.php';
|
||||
}
|
||||
|
|
|
@ -9,10 +9,6 @@ use Rector\Set\Contract\SetListInterface;
|
|||
*/
|
||||
final class DowngradeSetList implements SetListInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PHP_53 = __DIR__ . '/../../../config/set/downgrade-php53.php';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user