Updated Rector to commit f6858b86e32291df09751597abc8164fdd5a81c9

f6858b86e3 [DeadCode] Clean up double private method filtering on RemoveUnusedPrivateMethodRector (#6364)
This commit is contained in:
Tomas Votruba 2024-10-08 12:45:03 +00:00
parent 504b14ba36
commit 40e206a694
2 changed files with 9 additions and 13 deletions

View File

@ -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;

View File

@ -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
*/