From 010d5d2c6f7328c879ee4b4e5d75105495923b94 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 30 May 2023 13:05:48 +0000 Subject: [PATCH] Updated Rector to commit 22e97d1c418d0772cf449ed888522ca060829ddf https://github.com/rectorphp/rector-src/commit/22e97d1c418d0772cf449ed888522ca060829ddf Cleanup stmts (#4027) --- .../RemoveUnusedPrivatePropertyRector.php | 23 ++---------- .../Property/ReadOnlyPropertyRector.php | 37 +++++++++++-------- src/Application/VersionResolver.php | 4 +- src/NodeManipulator/PropertyManipulator.php | 19 +++++----- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 10 ++--- vendor/composer/autoload_static.php | 8 ++-- 7 files changed, 46 insertions(+), 57 deletions(-) diff --git a/rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php b/rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php index 52180674f05..065325e8a69 100644 --- a/rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php +++ b/rules/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector.php @@ -5,7 +5,6 @@ namespace Rector\DeadCode\Rector\Property; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; -use PhpParser\Node\Stmt\Nop; use PhpParser\Node\Stmt\Property; use PHPStan\Analyser\Scope; use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface; @@ -79,8 +78,8 @@ CODE_SAMPLE */ public function refactorWithScope(Node $node, Scope $scope) : ?Node { - $hasRemoved = \false; - foreach ($node->stmts as $key => $property) { + $hasChanged = \false; + foreach ($node->stmts as $property) { if (!$property instanceof Property) { continue; } @@ -94,24 +93,10 @@ CODE_SAMPLE // when already asssigned to true $isRemoved = $this->complexNodeRemover->removePropertyAndUsages($node, $property, $this->removeAssignSideEffect, $scope); if ($isRemoved) { - $this->processRemoveSameLineComment($node, $property, $key); - $hasRemoved = \true; + $hasChanged = \true; } } - return $hasRemoved ? $node : null; - } - private function processRemoveSameLineComment(Class_ $class, Property $property, int $key) : void - { - if (!isset($class->stmts[$key + 1])) { - return; - } - if (!$class->stmts[$key + 1] instanceof Nop) { - return; - } - if ($class->stmts[$key + 1]->getEndLine() !== $property->getStartLine()) { - return; - } - unset($class->stmts[$key + 1]); + return $hasChanged ? $node : null; } private function shouldSkipProperty(Property $property) : bool { diff --git a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php index 42238902c30..1ed45373558 100644 --- a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php +++ b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php @@ -98,28 +98,33 @@ CODE_SAMPLE */ public function getNodeTypes() : array { - return [Property::class, ClassMethod::class]; + return [Class_::class]; } /** - * @param Property|ClassMethod $node + * @param Class_ $node */ public function refactorWithScope(Node $node, Scope $scope) : ?Node { - if ($node instanceof ClassMethod) { - $hasChanged = \false; - foreach ($node->params as $param) { - $justChanged = $this->refactorParam($node, $param, $scope); - // different variable to ensure $hasChanged not replaced + $hasChanged = \false; + foreach ($node->getMethods() as $classMethod) { + foreach ($classMethod->params as $param) { + $justChanged = $this->refactorParam($node, $classMethod, $param, $scope); + // different variable to ensure $hasRemoved not replaced if ($justChanged instanceof Param) { $hasChanged = \true; } } - if ($hasChanged) { - return $node; - } - return null; } - return $this->refactorProperty($node, $scope); + foreach ($node->getProperties() as $property) { + $changedProperty = $this->refactorProperty($node, $property, $scope); + if ($changedProperty instanceof Property) { + $hasChanged = \true; + } + } + if ($hasChanged) { + return $node; + } + return null; } public function provideMinPhpVersion() : int { @@ -136,7 +141,7 @@ CODE_SAMPLE } return $class->isReadonly(); } - private function refactorProperty(Property $property, Scope $scope) : ?Property + private function refactorProperty(Class_ $class, Property $property, Scope $scope) : ?Property { // 1. is property read-only? if ($property->isReadonly()) { @@ -154,7 +159,7 @@ CODE_SAMPLE if (!$this->visibilityManipulator->hasVisibility($property, Visibility::PRIVATE)) { return null; } - if ($this->propertyManipulator->isPropertyChangeableExceptConstructor($property, $scope)) { + if ($this->propertyManipulator->isPropertyChangeableExceptConstructor($class, $property, $scope)) { return null; } if ($this->propertyFetchAssignManipulator->isAssignedMultipleTimesInConstructor($property)) { @@ -170,7 +175,7 @@ CODE_SAMPLE } return $property; } - private function refactorParam(ClassMethod $classMethod, Param $param, Scope $scope) : ?\PhpParser\Node\Param + private function refactorParam(Class_ $class, ClassMethod $classMethod, Param $param, Scope $scope) : ?\PhpParser\Node\Param { if (!$this->visibilityManipulator->hasVisibility($param, Visibility::PRIVATE)) { return null; @@ -179,7 +184,7 @@ CODE_SAMPLE return null; } // promoted property? - if ($this->propertyManipulator->isPropertyChangeableExceptConstructor($param, $scope)) { + if ($this->propertyManipulator->isPropertyChangeableExceptConstructor($class, $param, $scope)) { return null; } if ($this->visibilityManipulator->isReadonly($param)) { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index d2281d82e81..0801900827e 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '953ecb9ecd02d5fc13a21cd7086b60aa45eac31d'; + public const PACKAGE_VERSION = '22e97d1c418d0772cf449ed888522ca060829ddf'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-05-30 12:34:47'; + public const RELEASE_DATE = '2023-05-30 14:01:00'; /** * @var int */ diff --git a/src/NodeManipulator/PropertyManipulator.php b/src/NodeManipulator/PropertyManipulator.php index 0dc3d033ed9..b94029ecfcf 100644 --- a/src/NodeManipulator/PropertyManipulator.php +++ b/src/NodeManipulator/PropertyManipulator.php @@ -185,18 +185,10 @@ final class PropertyManipulator /** * @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $propertyOrParam */ - public function isPropertyChangeableExceptConstructor($propertyOrParam, Scope $scope) : bool + public function isPropertyChangeableExceptConstructor(Class_ $class, $propertyOrParam, Scope $scope) : bool { - $class = $this->betterNodeFinder->findParentType($propertyOrParam, Class_::class); - // does not have parent type ClassLike? Possibly parent is changed by other rule - if (!$class instanceof Class_) { - return \true; - } $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($class); - if ($phpDocInfo->hasByAnnotationClasses(self::ALLOWED_NOT_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES)) { - return \true; - } - if ($this->phpAttributeAnalyzer->hasPhpAttributes($class, self::ALLOWED_NOT_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES)) { + if ($this->hasAllowedNotReadonlyAnnotationOrAttribute($phpDocInfo, $class)) { return \true; } $propertyFetches = $this->propertyFetchFinder->findPrivatePropertyFetches($class, $propertyOrParam); @@ -333,4 +325,11 @@ final class PropertyManipulator } return \false; } + private function hasAllowedNotReadonlyAnnotationOrAttribute(PhpDocInfo $phpDocInfo, Class_ $class) : bool + { + if ($phpDocInfo->hasByAnnotationClasses(self::ALLOWED_NOT_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES)) { + return \true; + } + return $this->phpAttributeAnalyzer->hasPhpAttributes($class, self::ALLOWED_NOT_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES); + } } diff --git a/vendor/autoload.php b/vendor/autoload.php index 84bf725ff8c..3ce4cd98b3b 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit7c7e7770d5b992f14869cbba89680ca1::getLoader(); +return ComposerAutoloaderInit18ca20d17b299a5129994679ad8528a1::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 200dd8d56b7..62881c9614f 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit7c7e7770d5b992f14869cbba89680ca1 +class ComposerAutoloaderInit18ca20d17b299a5129994679ad8528a1 { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInit7c7e7770d5b992f14869cbba89680ca1 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit7c7e7770d5b992f14869cbba89680ca1', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit18ca20d17b299a5129994679ad8528a1', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit7c7e7770d5b992f14869cbba89680ca1', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit18ca20d17b299a5129994679ad8528a1', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit18ca20d17b299a5129994679ad8528a1::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInit18ca20d17b299a5129994679ad8528a1::$files; $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index e4d0011ac31..efc446a74ce 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1 +class ComposerStaticInit18ca20d17b299a5129994679ad8528a1 { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3085,9 +3085,9 @@ class ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit7c7e7770d5b992f14869cbba89680ca1::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit18ca20d17b299a5129994679ad8528a1::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit18ca20d17b299a5129994679ad8528a1::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit18ca20d17b299a5129994679ad8528a1::$classMap; }, null, ClassLoader::class); }