Skip to content

Commit

Permalink
Updated Rector to commit 7df4894bc7bd1bec704f8e428efb768d101e8984
Browse files Browse the repository at this point in the history
rectorphp/rector-src@7df4894 [Performance][DeadCode] Early check has private methods before find() on dynamic call checks on RemoveUnusedPrivateMethodRector (#5687)
  • Loading branch information
TomasVotruba committed Mar 4, 2024
1 parent 6fc0810 commit 9c44985
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,17 @@ public function getNodeTypes() : array
*/
public function refactorWithScope(Node $node, Scope $scope) : ?Node
{
if ($this->hasDynamicMethodCallOnFetchThis($node)) {
$classMethods = $node->getMethods();
if ($classMethods === []) {
return null;
}
if ($node->getMethods() === []) {
$filter = static function (ClassMethod $classMethod) : bool {
return $classMethod->isPrivate();
};
if (\array_filter($classMethods, $filter) === []) {
return null;
}
if ($this->hasDynamicMethodCallOnFetchThis($classMethods)) {
return null;
}
$hasChanged = \false;
Expand Down Expand Up @@ -113,7 +120,7 @@ private function shouldSkip(ClassMethod $classMethod, ?ClassReflection $classRef
if (!$classReflection instanceof ClassReflection) {
return \true;
}
// unreliable to detect trait, interface doesn't make sense
// unreliable to detect trait, interface, anonymous class: doesn't make sense
if ($classReflection->isTrait()) {
return \true;
}
Expand All @@ -123,7 +130,6 @@ private function shouldSkip(ClassMethod $classMethod, ?ClassReflection $classRef
if ($classReflection->isAnonymous()) {
return \true;
}
// skips interfaces by default too
if (!$classMethod->isPrivate()) {
return \true;
}
Expand All @@ -133,9 +139,12 @@ private function shouldSkip(ClassMethod $classMethod, ?ClassReflection $classRef
}
return $classReflection->hasMethod(MethodName::CALL);
}
private function hasDynamicMethodCallOnFetchThis(Class_ $class) : bool
/**
* @param ClassMethod[] $classMethods
*/
private function hasDynamicMethodCallOnFetchThis(array $classMethods) : bool
{
foreach ($class->getMethods() as $classMethod) {
foreach ($classMethods as $classMethod) {
$isFound = (bool) $this->betterNodeFinder->findFirst((array) $classMethod->getStmts(), function (Node $subNode) : bool {
if (!$subNode instanceof MethodCall) {
return \false;
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 = 'b4212ed99d3aadc3ce6371c984b644b54252752e';
public const PACKAGE_VERSION = '7df4894bc7bd1bec704f8e428efb768d101e8984';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-03-04 21:00:48';
public const RELEASE_DATE = '2024-03-05 00:12:12';
/**
* @var int
*/
Expand Down

0 comments on commit 9c44985

Please sign in to comment.