Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Mar 19, 2021
1 parent 2160f7c commit 0ced628
Showing 1 changed file with 1 addition and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,11 @@
namespace Rector\VendorLocker\Reflection;

use PHPStan\Reflection\ClassReflection;
use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer;

final class ClassReflectionAncestorAnalyzer
{
/**
* @var FamilyRelationsAnalyzer
*/
private $familyRelationsAnalyzer;

public function __construct(FamilyRelationsAnalyzer $familyRelationsAnalyzer)
{
$this->familyRelationsAnalyzer = $familyRelationsAnalyzer;
}

public function hasAncestors(ClassReflection $classReflection): bool
{
if ($classReflection->isClass()) {
// has at least interface
if ($classReflection->getInterfaces() !== []) {
return true;
}

// has at least one parent class
if ($classReflection->getParents() !== []) {
return true;
}

$childrenClassReflections = $this->familyRelationsAnalyzer->getChildrenOfClassReflection($classReflection);
return $childrenClassReflections !== [];
}

if ($classReflection->isInterface()) {
return $classReflection->getInterfaces() !== [];
}

return false;
return $classReflection->getAncestors() !== [$classReflection];
}
}

0 comments on commit 0ced628

Please sign in to comment.