From 40e206a694cd21527fd0bd46739eed9c64b45156 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 8 Oct 2024 12:45:03 +0000 Subject: [PATCH] Updated Rector to commit f6858b86e32291df09751597abc8164fdd5a81c9 https://github.com/rectorphp/rector-src/commit/f6858b86e32291df09751597abc8164fdd5a81c9 [DeadCode] Clean up double private method filtering on RemoveUnusedPrivateMethodRector (#6364) --- .../RemoveUnusedPrivateMethodRector.php | 18 +++++++----------- src/Application/VersionResolver.php | 4 ++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php b/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php index fef110f157a..7fbd8a46507 100644 --- a/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php +++ b/rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector.php @@ -11,6 +11,7 @@ use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use Rector\DeadCode\NodeAnalyzer\IsClassMethodUsedAnalyzer; +use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PhpParser\Node\BetterNodeFinder; use Rector\Rector\AbstractScopeAwareRector; use Rector\Reflection\ReflectionResolver; @@ -89,7 +90,8 @@ CODE_SAMPLE $filter = static function (ClassMethod $classMethod) : bool { return $classMethod->isPrivate(); }; - if (\array_filter($classMethods, $filter) === []) { + $privateMethods = \array_filter($classMethods, $filter); + if ($privateMethods === []) { return null; } if ($this->hasDynamicMethodCallOnFetchThis($classMethods)) { @@ -97,17 +99,14 @@ CODE_SAMPLE } $hasChanged = \false; $classReflection = $this->reflectionResolver->resolveClassReflection($node); - foreach ($node->stmts as $key => $stmt) { - if (!$stmt instanceof ClassMethod) { + foreach ($privateMethods as $privateMethod) { + if ($this->shouldSkip($privateMethod, $classReflection)) { continue; } - if ($this->shouldSkip($stmt, $classReflection)) { + if ($this->isClassMethodUsedAnalyzer->isClassMethodUsed($node, $privateMethod, $scope)) { continue; } - if ($this->isClassMethodUsedAnalyzer->isClassMethodUsed($node, $stmt, $scope)) { - continue; - } - unset($node->stmts[$key]); + unset($node->stmts[$privateMethod->getAttribute(AttributeKey::STMT_KEY)]); $hasChanged = \true; } if ($hasChanged) { @@ -130,9 +129,6 @@ CODE_SAMPLE if ($classReflection->isAnonymous()) { return \true; } - if (!$classMethod->isPrivate()) { - return \true; - } // skip magic methods - @see https://www.php.net/manual/en/language.oop5.magic.php if ($classMethod->isMagic()) { return \true; diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index b07ffd8b4ac..c90b1b17eb4 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 = '645aaa93cfa86b06db8de8d8671da91d81b4bddf'; + public const PACKAGE_VERSION = 'f6858b86e32291df09751597abc8164fdd5a81c9'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-10-08 17:43:58'; + public const RELEASE_DATE = '2024-10-08 19:42:37'; /** * @var int */