Skip to content

Commit

Permalink
Enhancement: Extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Jan 6, 2025
1 parent fb58818 commit 56fe987
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/Methods/PrivateInFinalClassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,8 @@ public function processNode(

$methodName = $node->name->toString();

$parentClass = $containingClass->getNativeReflection()->getParentClass();

if (
$parentClass instanceof \ReflectionClass
&& $parentClass->hasMethod($methodName)
) {
$parentMethod = $parentClass->getMethod($methodName);

if ($parentMethod->isProtected()) {
return [];
}
if (self::methodIsDeclaredByParentClass($containingClass, $methodName)) {
return [];
}

/** @var Reflection\ClassReflection $classReflection */
Expand Down Expand Up @@ -91,4 +82,21 @@ public function processNode(
->build(),
];
}

private static function methodIsDeclaredByParentClass(
Reflection\ClassReflection $containingClass,
string $methodName
): bool {
$parentClass = $containingClass->getNativeReflection()->getParentClass();

if (!$parentClass instanceof \ReflectionClass) {
return false;
}

if (!$parentClass->hasMethod($methodName)) {
return false;
}

return true;
}
}

0 comments on commit 56fe987

Please sign in to comment.