/** * @param ReflectionClass $class * * @return self */ public static function fromReflectionClass(ReflectionClass $class) { $type = 'class'; if ($class->isTrait()) { $type = 'trait'; } return new self(sprintf('Provided node "%s" is not interface, but "%s"', $class->getName(), $type)); }
/** * @dataProvider internalSymbolsProvider * * @param string $className * @throws \ReflectionException */ public function testCanReflectInternalClasses($className) { /* @var $class */ $phpInternalSourceLocator = new PhpInternalSourceLocator(); $reflector = new ClassReflector($phpInternalSourceLocator); try { $class = $reflector->reflect($className); } catch (\ReflectionException $e) { if ($phpInternalSourceLocator->hasStub($className)) { throw $e; } $this->markTestIncomplete(sprintf('Can\'t reflect class "%s" due to an internal reflection exception: "%s". Consider adding a stub class', $className, $e->getMessage())); } $this->assertInstanceOf(ReflectionClass::class, $class); $this->assertSame($className, $class->getName()); $this->assertTrue($class->isInternal()); $this->assertFalse($class->isUserDefined()); $internalReflection = new \ReflectionClass($className); $this->assertSame($internalReflection->isInterface(), $class->isInterface()); $this->assertSame($internalReflection->isTrait(), $class->isTrait()); }
/** * {@inheritDoc} */ public function isTrait() { return $this->betterReflectionClass->isTrait(); }
/** * getLongClassType returns the type of class: `Class`, `Interface` or `Trait`. * * @param \BetterReflection\Reflection\ReflectionClass $class * * @return string */ public function getLongClassType(ReflectionClass $class) { $type = 'Class'; if ($class->isInterface()) { $type = 'Interface'; } elseif ($class->isTrait()) { $type = 'Trait'; } return $type; }