mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit 7df4894bc7bd1bec704f8e428efb768d101e8984
7df4894bc7
[Performance][DeadCode] Early check has private methods before find() on dynamic call checks on RemoveUnusedPrivateMethodRector (#5687)
This commit is contained in:
parent
6fc08102f7
commit
9c449858d7
|
@ -82,10 +82,17 @@ CODE_SAMPLE
|
|||
*/
|
||||
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;
|
||||
|
@ -113,7 +120,7 @@ CODE_SAMPLE
|
|||
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;
|
||||
}
|
||||
|
@ -123,7 +130,6 @@ CODE_SAMPLE
|
|||
if ($classReflection->isAnonymous()) {
|
||||
return \true;
|
||||
}
|
||||
// skips interfaces by default too
|
||||
if (!$classMethod->isPrivate()) {
|
||||
return \true;
|
||||
}
|
||||
|
@ -133,9 +139,12 @@ CODE_SAMPLE
|
|||
}
|
||||
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;
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue