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
 /**
  * {@inheritDoc}
  */
 public function getParentClass()
 {
     $parentClass = $this->betterReflectionClass->getParentClass();
     if (null === $parentClass) {
         return null;
     }
     return new self($parentClass);
 }
Esempio n. 2
0
 /**
  * collects all interfaces for current class (only self implemented ones).
  *
  * @param ReflectionClass $class
  * @param string          $prefix
  * @param string          $suffix
  *
  * @return array
  */
 protected function buildInterfaces(ReflectionClass $class, $prefix = '<<', $suffix = '>>')
 {
     try {
         $parentInterfaces = $class->getParentClass() ? $class->getParentClass()->getInterfaces() : [];
     } catch (IdentifierNotFound $e) {
         $parentInterfaces = [];
     }
     $interfaces = array_diff($class->getImmediateInterfaces(), $parentInterfaces);
     foreach ($interfaces as $key => $interface) {
         $interfaces[$key] = $prefix . $this->prepare($interface) . $suffix;
     }
     natcasesort($interfaces);
     return $interfaces;
 }
 private function assertSameClassAttributes(\ReflectionClass $original, ReflectionClass $stubbed)
 {
     $this->assertSame($original->getName(), $stubbed->getName());
     $internalParent = $original->getParentClass();
     $betterParent = $stubbed->getParentClass();
     $internalParentName = $internalParent ? $internalParent->getName() : null;
     $betterParentName = $betterParent ? $betterParent->getName() : null;
     $this->assertSame($internalParentName, $betterParentName);
     $originalMethods = $original->getMethods();
     $originalMethodNames = array_map(function (\ReflectionMethod $method) {
         return $method->getName();
     }, $originalMethods);
     $stubbedMethodNames = array_map(function (ReflectionMethod $method) {
         return $method->getName();
     }, $stubbed->getMethods());
     sort($originalMethodNames);
     sort($stubbedMethodNames);
     $this->assertSame($originalMethodNames, $stubbedMethodNames);
     $this->assertEquals($original->getConstants(), $stubbed->getConstants());
     foreach ($originalMethods as $method) {
         $this->assertSameMethodAttributes($method, $stubbed->getMethod($method->getName()));
     }
 }