Skip to content

Commit

Permalink
Updated Rector to commit f6858b86e32291df09751597abc8164fdd5a81c9
Browse files Browse the repository at this point in the history
rectorphp/rector-src@f6858b8 [DeadCode] Clean up double private method filtering on RemoveUnusedPrivateMethodRector (#6364)
  • Loading branch information
TomasVotruba committed Oct 8, 2024
1 parent 504b14b commit 40e206a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -89,25 +90,23 @@ public function refactorWithScope(Node $node, Scope $scope) : ?Node
$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)) {
return null;
}
$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) {
Expand All @@ -130,9 +129,6 @@ private function shouldSkip(ClassMethod $classMethod, ?ClassReflection $classRef
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;
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 40e206a

Please sign in to comment.