diff --git a/src/Rules/DeadCode/UnusedPrivateMethodRule.php b/src/Rules/DeadCode/UnusedPrivateMethodRule.php index 2c1ab6ce64..fbe4cf5db5 100644 --- a/src/Rules/DeadCode/UnusedPrivateMethodRule.php +++ b/src/Rules/DeadCode/UnusedPrivateMethodRule.php @@ -155,6 +155,14 @@ public function processNode(Node $node, Scope $scope): array return []; } + $inMethod = $arrayScope->getFunction(); + if (!$inMethod instanceof MethodReflection) { + continue; + } + if ($inMethod->getName() === $typeAndMethod->getMethod()) { + continue; + } + $calledOnType = $typeAndMethod->getType(); $methodReflection = $arrayScope->getMethodReflection($calledOnType, $typeAndMethod->getMethod()); if ($methodReflection === null) { @@ -165,13 +173,6 @@ public function processNode(Node $node, Scope $scope): array continue; } - $inMethod = $arrayScope->getFunction(); - if (!$inMethod instanceof MethodReflection) { - continue; - } - if ($inMethod->getName() === $typeAndMethod->getMethod()) { - continue; - } unset($methods[strtolower($typeAndMethod->getMethod())]); } } diff --git a/src/Rules/Methods/CallPrivateMethodThroughStaticRule.php b/src/Rules/Methods/CallPrivateMethodThroughStaticRule.php index 327b2ba473..05cdafe663 100644 --- a/src/Rules/Methods/CallPrivateMethodThroughStaticRule.php +++ b/src/Rules/Methods/CallPrivateMethodThroughStaticRule.php @@ -38,6 +38,10 @@ public function processNode(Node $node, Scope $scope): array return []; } + if ($scope->isInClass() && $scope->getClassReflection()->isFinal()) { + return []; + } + $classType = $scope->resolveTypeByName($className); if (!$classType->hasMethod($methodName)->yes()) { return []; @@ -48,10 +52,6 @@ public function processNode(Node $node, Scope $scope): array return []; } - if ($scope->isInClass() && $scope->getClassReflection()->isFinal()) { - return []; - } - return [ RuleErrorBuilder::message(sprintf( 'Unsafe call to private method %s::%s() through static::.',