public function testFromTrait() { $sourceLocator = new SingleFileSourceLocator(__DIR__ . '/../../Fixture/ExampleClass.php'); $reflector = new ClassReflector($sourceLocator); $exception = NotAnInterfaceReflection::fromReflectionClass($reflector->reflect(Fixture\ExampleTrait::class)); $this->assertInstanceOf(NotAnInterfaceReflection::class, $exception); $this->assertSame('Provided node "' . Fixture\ExampleTrait::class . '" is not interface, but "trait"', $exception->getMessage()); }
/** * This method allows us to retrieve all interfaces parent of the this interface. Do not use on class nodes! * * @return ReflectionClass[] parent interfaces of this interface */ private function getInterfacesHierarchy() { if (!$this->isInterface()) { throw NotAnInterfaceReflection::fromReflectionClass($this); } /* @var $node InterfaceNode */ $node = $this->node; return array_merge([$this->getName() => $this], ...array_map(function (Node\Name $interfaceName) { return $this->reflectClassForNamedNode($interfaceName)->getInterfacesHierarchy(); }, $node->extends)); }