From a4b3da989a8abb612b81f781bcd9f657a727dc0e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 4 Sep 2021 07:43:00 +0000 Subject: [PATCH] Updated Rector to commit d2545a5d93763a111957fc1beafe380b31bd557b https://github.com/rectorphp/rector-src/commit/d2545a5d93763a111957fc1beafe380b31bd557b [Renaming] Handle ClassLike property on RenamePropertyRector (#825) --- .../PropertyFetch/RenamePropertyRector.php | 61 ++++++++++++------- src/Application/VersionResolver.php | 4 +- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 14 ++--- vendor/composer/autoload_static.php | 8 +-- vendor/scoper-autoload.php | 10 +-- 6 files changed, 59 insertions(+), 40 deletions(-) diff --git a/rules/Renaming/Rector/PropertyFetch/RenamePropertyRector.php b/rules/Renaming/Rector/PropertyFetch/RenamePropertyRector.php index 896df23a757..004508a0033 100644 --- a/rules/Renaming/Rector/PropertyFetch/RenamePropertyRector.php +++ b/rules/Renaming/Rector/PropertyFetch/RenamePropertyRector.php @@ -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 $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; + } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index a20bada8fdf..7239e5024e9 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -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__); diff --git a/vendor/autoload.php b/vendor/autoload.php index d897dd5f692..b2d7f7833a7 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit3d306b9d04d959b95cf44fc862df9ad5::getLoader(); +return ComposerAutoloaderInit04dcd1098fde6120aab79eb8472964fe::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index ccbd2b26571..61dde5f9f9f 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -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; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 19794515231..1e2a886a2bd 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -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); } diff --git a/vendor/scoper-autoload.php b/vendor/scoper-autoload.php index 040795f3a65..60ee587054c 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('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')) {