mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 01:40:49 +00:00
fc10fce13d
* re-enable rectify and ecs * [Rectify] [Php81] Enable Rectify on Readonly Property only * comment * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify Co-authored-by: GitHub Action <action@github.com>
62 lines
2.0 KiB
PHP
62 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Rector\FamilyTree\NodeAnalyzer;
|
|
|
|
use PHPStan\Reflection\ClassReflection;
|
|
use PHPStan\Reflection\Php\PhpMethodReflection;
|
|
use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer;
|
|
|
|
final class ClassChildAnalyzer
|
|
{
|
|
public function __construct(
|
|
private readonly FamilyRelationsAnalyzer $familyRelationsAnalyzer
|
|
) {
|
|
}
|
|
|
|
public function hasChildClassMethod(ClassReflection $classReflection, string $methodName): bool
|
|
{
|
|
$childrenClassReflections = $this->familyRelationsAnalyzer->getChildrenOfClassReflection($classReflection);
|
|
|
|
foreach ($childrenClassReflections as $childClassReflection) {
|
|
if (! $childClassReflection->hasNativeMethod($methodName)) {
|
|
continue;
|
|
}
|
|
|
|
$constructorReflectionMethod = $childClassReflection->getNativeMethod($methodName);
|
|
if (! $constructorReflectionMethod instanceof PhpMethodReflection) {
|
|
continue;
|
|
}
|
|
|
|
$methodDeclaringClassReflection = $constructorReflectionMethod->getDeclaringClass();
|
|
if ($methodDeclaringClassReflection->getName() === $childClassReflection->getName()) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function hasParentClassMethod(ClassReflection $classReflection, string $methodName): bool
|
|
{
|
|
foreach ($classReflection->getParents() as $parentClassReflections) {
|
|
if (! $parentClassReflections->hasMethod($methodName)) {
|
|
continue;
|
|
}
|
|
|
|
$constructMethodReflection = $parentClassReflections->getNativeMethod($methodName);
|
|
if (! $constructMethodReflection instanceof PhpMethodReflection) {
|
|
continue;
|
|
}
|
|
|
|
$methodDeclaringMethodClass = $constructMethodReflection->getDeclaringClass();
|
|
if ($methodDeclaringMethodClass->getName() === $parentClassReflections->getName()) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|