Skip to content

Commit ef7e5b9

Browse files
authored
CallPrivateMethodThroughStaticRule: cheap checks first
1 parent 6e3130a commit ef7e5b9

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/Rules/DeadCode/UnusedPrivateMethodRule.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ public function processNode(Node $node, Scope $scope): array
155155
return [];
156156
}
157157

158+
$inMethod = $arrayScope->getFunction();
159+
if (!$inMethod instanceof MethodReflection) {
160+
continue;
161+
}
162+
if ($inMethod->getName() === $typeAndMethod->getMethod()) {
163+
continue;
164+
}
165+
158166
$calledOnType = $typeAndMethod->getType();
159167
$methodReflection = $arrayScope->getMethodReflection($calledOnType, $typeAndMethod->getMethod());
160168
if ($methodReflection === null) {
@@ -165,13 +173,6 @@ public function processNode(Node $node, Scope $scope): array
165173
continue;
166174
}
167175

168-
$inMethod = $arrayScope->getFunction();
169-
if (!$inMethod instanceof MethodReflection) {
170-
continue;
171-
}
172-
if ($inMethod->getName() === $typeAndMethod->getMethod()) {
173-
continue;
174-
}
175176
unset($methods[strtolower($typeAndMethod->getMethod())]);
176177
}
177178
}

src/Rules/Methods/CallPrivateMethodThroughStaticRule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public function processNode(Node $node, Scope $scope): array
3838
return [];
3939
}
4040

41+
if ($scope->isInClass() && $scope->getClassReflection()->isFinal()) {
42+
return [];
43+
}
44+
4145
$classType = $scope->resolveTypeByName($className);
4246
if (!$classType->hasMethod($methodName)->yes()) {
4347
return [];
@@ -48,10 +52,6 @@ public function processNode(Node $node, Scope $scope): array
4852
return [];
4953
}
5054

51-
if ($scope->isInClass() && $scope->getClassReflection()->isFinal()) {
52-
return [];
53-
}
54-
5555
return [
5656
RuleErrorBuilder::message(sprintf(
5757
'Unsafe call to private method %s::%s() through static::.',

0 commit comments

Comments
 (0)