/** * Creates a Descriptor from the provided data. * * @param InterfaceReflector $data * * @return InterfaceDescriptor */ public function create($data) { $interfaceDescriptor = new InterfaceDescriptor(); $interfaceDescriptor->setFullyQualifiedStructuralElementName($data->getName()); $interfaceDescriptor->setName($data->getShortName()); $interfaceDescriptor->setLine($data->getLinenumber()); $interfaceDescriptor->setPackage($this->extractPackageFromDocBlock($data->getDocBlock()) ?: ''); // Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself $interfaceDescriptor->setNamespace('\\' . (strtolower($data->getNamespace()) == 'global' ? '' : $data->getNamespace())); $this->assembleDocBlock($data->getDocBlock(), $interfaceDescriptor); $this->addConstants($data->getConstants(), $interfaceDescriptor); $this->addMethods($data->getMethods(), $interfaceDescriptor); foreach ($data->getParentInterfaces() as $interfaceClassName) { $interfaceDescriptor->getParent()->set($interfaceClassName, $interfaceClassName); } return $interfaceDescriptor; }
/** * @covers phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::execute * @covers phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::addElementsOfTypeToNamespace */ public function testAddInterfaceToNamespace() { $interface = new InterfaceDescriptor(); $interface->setNamespace('My\\Space'); $interface->setFullyQualifiedStructuralElementName('My\\Space\\Interface1'); $this->project->getFiles()->get(0)->getInterfaces()->add($interface); // double check if a second interface in the same deep namespace ends up at the right location $interface2 = new InterfaceDescriptor(); $interface2->setNamespace('My\\Space'); $interface2->setFullyQualifiedStructuralElementName('My\\Space\\Interface2'); $this->project->getFiles()->get(0)->getInterfaces()->add($interface2); $this->fixture->execute($this->project); $this->assertSame(array($interface, $interface2), $this->project->getNamespace()->getChildren()->get('My')->getChildren()->get('Space')->getInterfaces()->getAll()); }