Updated Rector to commit 82de3667411f8e6e9461d0a7f48974badab957c0

82de366741 [Downgrade PHP 5.4] Add DowngradeInstanceMethodCallRector (#1226)
This commit is contained in:
Tomas Votruba 2021-11-13 20:02:56 +00:00
parent cbf5a11580
commit 96796ca64a
8 changed files with 108 additions and 19 deletions

View File

@ -9,6 +9,7 @@ use Rector\DowngradePhp54\Rector\Array_\ShortArrayToLongArrayRector;
use Rector\DowngradePhp54\Rector\Closure\DowngradeStaticClosureRector;
use Rector\DowngradePhp54\Rector\FunctionLike\DowngradeCallableTypeDeclarationRector;
use Rector\DowngradePhp54\Rector\LNumber\DowngradeBinaryNotationRector;
use Rector\DowngradePhp54\Rector\MethodCall\DowngradeInstanceMethodCallRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator $containerConfigurator) : void {
$parameters = $containerConfigurator->parameters();
@ -18,4 +19,5 @@ return static function (\Symfony\Component\DependencyInjection\Loader\Configurat
$services->set(\Rector\DowngradePhp54\Rector\Closure\DowngradeStaticClosureRector::class);
$services->set(\Rector\DowngradePhp54\Rector\FunctionLike\DowngradeCallableTypeDeclarationRector::class);
$services->set(\Rector\DowngradePhp54\Rector\LNumber\DowngradeBinaryNotationRector::class);
$services->set(\Rector\DowngradePhp54\Rector\MethodCall\DowngradeInstanceMethodCallRector::class);
};

View File

@ -0,0 +1,85 @@
<?php
declare (strict_types=1);
namespace Rector\DowngradePhp54\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Clone_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Expression;
use Rector\Core\Rector\AbstractRector;
use Rector\Naming\Naming\VariableNaming;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://wiki.php.net/rfc/instance-method-call
*
* @see \Rector\Tests\DowngradePhp54\Rector\MethodCall\DowngradeInstanceMethodCallRector\DowngradeInstanceMethodCallRectorTest
*/
final class DowngradeInstanceMethodCallRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @var \Rector\Naming\Naming\VariableNaming
*/
private $variableNaming;
public function __construct(\Rector\Naming\Naming\VariableNaming $variableNaming)
{
$this->variableNaming = $variableNaming;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Downgrade instance and method call/property access', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
echo (new \ReflectionClass('\\stdClass'))->getName();
CODE_SAMPLE
, <<<'CODE_SAMPLE'
$object = new \ReflectionClass('\\stdClass');
echo $object->getName();
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Expr\MethodCall::class, \PhpParser\Node\Expr\PropertyFetch::class, \PhpParser\Node\Expr\ArrayDimFetch::class];
}
/**
* @param ArrayDimFetch|MethodCall|PropertyFetch $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
if ($this->shouldSkip($node)) {
return null;
}
$variable = $this->createVariable($node);
$expression = new \PhpParser\Node\Stmt\Expression(new \PhpParser\Node\Expr\Assign($variable, $node->var));
$this->nodesToAddCollector->addNodeBeforeNode($expression, $node);
$node->var = $variable;
// necessary to remove useless parentheses
$node->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NODE, null);
return $node;
}
/**
* @param \PhpParser\Node\Expr\ArrayDimFetch|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\PropertyFetch $node
*/
private function shouldSkip($node) : bool
{
if ($node->var instanceof \PhpParser\Node\Expr\New_) {
return \false;
}
return !$node->var instanceof \PhpParser\Node\Expr\Clone_;
}
private function createVariable(\PhpParser\Node $node) : \PhpParser\Node\Expr\Variable
{
$currentStmt = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT);
$scope = $currentStmt->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
return new \PhpParser\Node\Expr\Variable($this->variableNaming->createCountedValueName('object', $scope));
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '2334331e30b65079071ee46c1e00a10c7c93be2d';
public const PACKAGE_VERSION = '82de3667411f8e6e9461d0a7f48974badab957c0';
/**
* @var string
*/
public const RELEASE_DATE = '2021-11-13 17:08:37';
public const RELEASE_DATE = '2021-11-13 22:47:32';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20211113\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 ComposerAutoloaderInit31981303893d54560204e228819fdcd8::getLoader();
return ComposerAutoloaderInit72ff406b03dad4762ea3e580ab656936::getLoader();

View File

@ -1798,6 +1798,7 @@ return array(
'Rector\\DowngradePhp54\\Rector\\Closure\\DowngradeStaticClosureRector' => $baseDir . '/rules/DowngradePhp54/Rector/Closure/DowngradeStaticClosureRector.php',
'Rector\\DowngradePhp54\\Rector\\FunctionLike\\DowngradeCallableTypeDeclarationRector' => $baseDir . '/rules/DowngradePhp54/Rector/FunctionLike/DowngradeCallableTypeDeclarationRector.php',
'Rector\\DowngradePhp54\\Rector\\LNumber\\DowngradeBinaryNotationRector' => $baseDir . '/rules/DowngradePhp54/Rector/LNumber/DowngradeBinaryNotationRector.php',
'Rector\\DowngradePhp54\\Rector\\MethodCall\\DowngradeInstanceMethodCallRector' => $baseDir . '/rules/DowngradePhp54/Rector/MethodCall/DowngradeInstanceMethodCallRector.php',
'Rector\\DowngradePhp55\\Rector\\ClassConstFetch\\DowngradeClassConstantToStringRector' => $baseDir . '/rules/DowngradePhp55/Rector/ClassConstFetch/DowngradeClassConstantToStringRector.php',
'Rector\\DowngradePhp56\\NodeManipulator\\ArgManipulator' => $baseDir . '/rules/DowngradePhp56/NodeManipulator/ArgManipulator.php',
'Rector\\DowngradePhp56\\NodeManipulator\\UnpackedArgList' => $baseDir . '/rules/DowngradePhp56/NodeManipulator/UnpackedArgList.php',

View File

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

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit31981303893d54560204e228819fdcd8
class ComposerStaticInit72ff406b03dad4762ea3e580ab656936
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -2128,6 +2128,7 @@ class ComposerStaticInit31981303893d54560204e228819fdcd8
'Rector\\DowngradePhp54\\Rector\\Closure\\DowngradeStaticClosureRector' => __DIR__ . '/../..' . '/rules/DowngradePhp54/Rector/Closure/DowngradeStaticClosureRector.php',
'Rector\\DowngradePhp54\\Rector\\FunctionLike\\DowngradeCallableTypeDeclarationRector' => __DIR__ . '/../..' . '/rules/DowngradePhp54/Rector/FunctionLike/DowngradeCallableTypeDeclarationRector.php',
'Rector\\DowngradePhp54\\Rector\\LNumber\\DowngradeBinaryNotationRector' => __DIR__ . '/../..' . '/rules/DowngradePhp54/Rector/LNumber/DowngradeBinaryNotationRector.php',
'Rector\\DowngradePhp54\\Rector\\MethodCall\\DowngradeInstanceMethodCallRector' => __DIR__ . '/../..' . '/rules/DowngradePhp54/Rector/MethodCall/DowngradeInstanceMethodCallRector.php',
'Rector\\DowngradePhp55\\Rector\\ClassConstFetch\\DowngradeClassConstantToStringRector' => __DIR__ . '/../..' . '/rules/DowngradePhp55/Rector/ClassConstFetch/DowngradeClassConstantToStringRector.php',
'Rector\\DowngradePhp56\\NodeManipulator\\ArgManipulator' => __DIR__ . '/../..' . '/rules/DowngradePhp56/NodeManipulator/ArgManipulator.php',
'Rector\\DowngradePhp56\\NodeManipulator\\UnpackedArgList' => __DIR__ . '/../..' . '/rules/DowngradePhp56/NodeManipulator/UnpackedArgList.php',
@ -3541,9 +3542,9 @@ class ComposerStaticInit31981303893d54560204e228819fdcd8
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit31981303893d54560204e228819fdcd8::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit31981303893d54560204e228819fdcd8::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit31981303893d54560204e228819fdcd8::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit72ff406b03dad4762ea3e580ab656936::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit72ff406b03dad4762ea3e580ab656936::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit72ff406b03dad4762ea3e580ab656936::$classMap;
}, null, ClassLoader::class);
}

View File

@ -12,8 +12,8 @@ if (!class_exists('GenerateChangelogCommand', false) && !interface_exists('Gener
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20211113\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit31981303893d54560204e228819fdcd8', false) && !interface_exists('ComposerAutoloaderInit31981303893d54560204e228819fdcd8', false) && !trait_exists('ComposerAutoloaderInit31981303893d54560204e228819fdcd8', false)) {
spl_autoload_call('RectorPrefix20211113\ComposerAutoloaderInit31981303893d54560204e228819fdcd8');
if (!class_exists('ComposerAutoloaderInit72ff406b03dad4762ea3e580ab656936', false) && !interface_exists('ComposerAutoloaderInit72ff406b03dad4762ea3e580ab656936', false) && !trait_exists('ComposerAutoloaderInit72ff406b03dad4762ea3e580ab656936', false)) {
spl_autoload_call('RectorPrefix20211113\ComposerAutoloaderInit72ff406b03dad4762ea3e580ab656936');
}
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('RectorPrefix20211113\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -3309,9 +3309,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20211113\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire31981303893d54560204e228819fdcd8')) {
function composerRequire31981303893d54560204e228819fdcd8() {
return \RectorPrefix20211113\composerRequire31981303893d54560204e228819fdcd8(...func_get_args());
if (!function_exists('composerRequire72ff406b03dad4762ea3e580ab656936')) {
function composerRequire72ff406b03dad4762ea3e580ab656936() {
return \RectorPrefix20211113\composerRequire72ff406b03dad4762ea3e580ab656936(...func_get_args());
}
}
if (!function_exists('parseArgs')) {