mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 06:18:07 +01:00
Updated Rector to commit d2545a5d93763a111957fc1beafe380b31bd557b
d2545a5d93
[Renaming] Handle ClassLike property on RenamePropertyRector (#825)
This commit is contained in:
parent
d62e039ac8
commit
a4b3da989a
@ -39,33 +39,17 @@ final class RenamePropertyRector extends \Rector\Core\Rector\AbstractRector impl
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [\PhpParser\Node\Expr\PropertyFetch::class];
|
||||
return [\PhpParser\Node\Expr\PropertyFetch::class, \PhpParser\Node\Stmt\ClassLike::class];
|
||||
}
|
||||
/**
|
||||
* @param PropertyFetch $node
|
||||
* @param PropertyFetch|ClassLike $node
|
||||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
$class = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NODE);
|
||||
foreach ($this->renamedProperties as $renamedProperty) {
|
||||
if (!$this->isObjectType($node->var, $renamedProperty->getObjectType())) {
|
||||
continue;
|
||||
}
|
||||
$oldProperty = $renamedProperty->getOldProperty();
|
||||
if (!$this->isName($node, $oldProperty)) {
|
||||
continue;
|
||||
}
|
||||
$nodeVarType = $this->nodeTypeResolver->resolve($node->var);
|
||||
if ($nodeVarType instanceof \PHPStan\Type\ThisType && $class instanceof \PhpParser\Node\Stmt\ClassLike) {
|
||||
$property = $class->getProperty($oldProperty);
|
||||
if ($property instanceof \PhpParser\Node\Stmt\Property) {
|
||||
$property->props[0]->name = new \PhpParser\Node\VarLikeIdentifier($renamedProperty->getNewProperty());
|
||||
}
|
||||
}
|
||||
$node->name = new \PhpParser\Node\Identifier($renamedProperty->getNewProperty());
|
||||
return $node;
|
||||
if ($node instanceof \PhpParser\Node\Stmt\ClassLike) {
|
||||
return $this->processFromClassLike($node);
|
||||
}
|
||||
return null;
|
||||
return $this->processFromPropertyFetch($node);
|
||||
}
|
||||
/**
|
||||
* @param array<string, RenameProperty[]> $configuration
|
||||
@ -76,4 +60,39 @@ final class RenamePropertyRector extends \Rector\Core\Rector\AbstractRector impl
|
||||
\RectorPrefix20210904\Webmozart\Assert\Assert::allIsInstanceOf($renamedProperties, \Rector\Renaming\ValueObject\RenameProperty::class);
|
||||
$this->renamedProperties = $renamedProperties;
|
||||
}
|
||||
private function processFromClassLike(\PhpParser\Node\Stmt\ClassLike $classLike) : \PhpParser\Node\Stmt\ClassLike
|
||||
{
|
||||
foreach ($this->renamedProperties as $renamedProperty) {
|
||||
$this->renameProperty($classLike, $renamedProperty);
|
||||
}
|
||||
return $classLike;
|
||||
}
|
||||
private function renameProperty(\PhpParser\Node\Stmt\ClassLike $classLike, \Rector\Renaming\ValueObject\RenameProperty $renameProperty) : void
|
||||
{
|
||||
$property = $classLike->getProperty($renameProperty->getOldProperty());
|
||||
if (!$property instanceof \PhpParser\Node\Stmt\Property) {
|
||||
return;
|
||||
}
|
||||
$property->props[0]->name = new \PhpParser\Node\VarLikeIdentifier($renameProperty->getNewProperty());
|
||||
}
|
||||
private function processFromPropertyFetch(\PhpParser\Node\Expr\PropertyFetch $propertyFetch) : ?\PhpParser\Node\Expr\PropertyFetch
|
||||
{
|
||||
$class = $propertyFetch->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CLASS_NODE);
|
||||
foreach ($this->renamedProperties as $renamedProperty) {
|
||||
if (!$this->isObjectType($propertyFetch->var, $renamedProperty->getObjectType())) {
|
||||
continue;
|
||||
}
|
||||
$oldProperty = $renamedProperty->getOldProperty();
|
||||
if (!$this->isName($propertyFetch, $oldProperty)) {
|
||||
continue;
|
||||
}
|
||||
$nodeVarType = $this->nodeTypeResolver->resolve($propertyFetch->var);
|
||||
if ($nodeVarType instanceof \PHPStan\Type\ThisType && $class instanceof \PhpParser\Node\Stmt\ClassLike) {
|
||||
$this->renameProperty($class, $renamedProperty);
|
||||
}
|
||||
$propertyFetch->name = new \PhpParser\Node\Identifier($renamedProperty->getNewProperty());
|
||||
return $propertyFetch;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,11 @@ final class VersionResolver
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '61709a198d9079071857fb14de0b21482d996a5d';
|
||||
public const PACKAGE_VERSION = 'd2545a5d93763a111957fc1beafe380b31bd557b';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-09-04 09:29:37';
|
||||
public const RELEASE_DATE = '2021-09-04 09:30:17';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20210904\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit3d306b9d04d959b95cf44fc862df9ad5::getLoader();
|
||||
return ComposerAutoloaderInit04dcd1098fde6120aab79eb8472964fe::getLoader();
|
||||
|
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 ComposerAutoloaderInit3d306b9d04d959b95cf44fc862df9ad5
|
||||
class ComposerAutoloaderInit04dcd1098fde6120aab79eb8472964fe
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,15 +22,15 @@ class ComposerAutoloaderInit3d306b9d04d959b95cf44fc862df9ad5
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit3d306b9d04d959b95cf44fc862df9ad5', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit04dcd1098fde6120aab79eb8472964fe', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit3d306b9d04d959b95cf44fc862df9ad5', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit04dcd1098fde6120aab79eb8472964fe', '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\ComposerStaticInit3d306b9d04d959b95cf44fc862df9ad5::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit04dcd1098fde6120aab79eb8472964fe::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
@ -42,19 +42,19 @@ class ComposerAutoloaderInit3d306b9d04d959b95cf44fc862df9ad5
|
||||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit3d306b9d04d959b95cf44fc862df9ad5::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit04dcd1098fde6120aab79eb8472964fe::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire3d306b9d04d959b95cf44fc862df9ad5($fileIdentifier, $file);
|
||||
composerRequire04dcd1098fde6120aab79eb8472964fe($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire3d306b9d04d959b95cf44fc862df9ad5($fileIdentifier, $file)
|
||||
function composerRequire04dcd1098fde6120aab79eb8472964fe($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit3d306b9d04d959b95cf44fc862df9ad5
|
||||
class ComposerStaticInit04dcd1098fde6120aab79eb8472964fe
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
@ -3856,9 +3856,9 @@ class ComposerStaticInit3d306b9d04d959b95cf44fc862df9ad5
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit3d306b9d04d959b95cf44fc862df9ad5::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit3d306b9d04d959b95cf44fc862df9ad5::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit3d306b9d04d959b95cf44fc862df9ad5::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit04dcd1098fde6120aab79eb8472964fe::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit04dcd1098fde6120aab79eb8472964fe::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit04dcd1098fde6120aab79eb8472964fe::$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('RectorPrefix20210904\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit3d306b9d04d959b95cf44fc862df9ad5', false) && !interface_exists('ComposerAutoloaderInit3d306b9d04d959b95cf44fc862df9ad5', false) && !trait_exists('ComposerAutoloaderInit3d306b9d04d959b95cf44fc862df9ad5', false)) {
|
||||
spl_autoload_call('RectorPrefix20210904\ComposerAutoloaderInit3d306b9d04d959b95cf44fc862df9ad5');
|
||||
if (!class_exists('ComposerAutoloaderInit04dcd1098fde6120aab79eb8472964fe', false) && !interface_exists('ComposerAutoloaderInit04dcd1098fde6120aab79eb8472964fe', false) && !trait_exists('ComposerAutoloaderInit04dcd1098fde6120aab79eb8472964fe', false)) {
|
||||
spl_autoload_call('RectorPrefix20210904\ComposerAutoloaderInit04dcd1098fde6120aab79eb8472964fe');
|
||||
}
|
||||
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('RectorPrefix20210904\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
@ -3311,9 +3311,9 @@ if (!function_exists('print_node')) {
|
||||
return \RectorPrefix20210904\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire3d306b9d04d959b95cf44fc862df9ad5')) {
|
||||
function composerRequire3d306b9d04d959b95cf44fc862df9ad5() {
|
||||
return \RectorPrefix20210904\composerRequire3d306b9d04d959b95cf44fc862df9ad5(...func_get_args());
|
||||
if (!function_exists('composerRequire04dcd1098fde6120aab79eb8472964fe')) {
|
||||
function composerRequire04dcd1098fde6120aab79eb8472964fe() {
|
||||
return \RectorPrefix20210904\composerRequire04dcd1098fde6120aab79eb8472964fe(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user