BetterReflection\Reflection\ReflectionClass::getParentClass PHP Method

getParentClass() public method

You may optionally specify a source locator that will be used to locate the parent class. If no source locator is given, a default will be used.
public getParentClass ( ) : ReflectionClass
return ReflectionClass
    public function getParentClass()
    {
        if (!$this->node instanceof ClassNode || null === $this->node->extends) {
            return null;
        }
        $objectType = (new FindTypeFromAst())->__invoke($this->node->extends, $this->locatedSource, $this->getNamespaceName());
        if (null === $objectType || !$objectType instanceof Object_) {
            return null;
        }
        // @TODO use actual `ClassReflector` or `FunctionReflector`?
        /* @var $parent self */
        $parent = $this->reflector->reflect((string) $objectType->getFqsen());
        if ($parent->isInterface() || $parent->isTrait()) {
            throw NotAClassReflection::fromReflectionClass($parent);
        }
        return $parent;
    }

Usage Example

 /**
  * {@inheritDoc}
  */
 public function getParentClass()
 {
     $parentClass = $this->betterReflectionClass->getParentClass();
     if (null === $parentClass) {
         return null;
     }
     return new self($parentClass);
 }
All Usage Examples Of BetterReflection\Reflection\ReflectionClass::getParentClass