/** * Creates a Descriptor from the provided data. * * @param TraitReflector $data * * @return TraitDescriptor */ public function create($data) { $traitDescriptor = new TraitDescriptor(); $traitDescriptor->setFullyQualifiedStructuralElementName($data->getName()); $traitDescriptor->setName($data->getShortName()); $traitDescriptor->setLine($data->getLinenumber()); $traitDescriptor->setPackage($this->extractPackageFromDocBlock($data->getDocBlock()) ?: ''); // Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself $traitDescriptor->setNamespace('\\' . (strtolower($data->getNamespace()) == 'global' ? '' : $data->getNamespace())); $this->assembleDocBlock($data->getDocBlock(), $traitDescriptor); $this->addProperties($data->getProperties(), $traitDescriptor); $this->addMethods($data->getMethods(), $traitDescriptor); return $traitDescriptor; }
/** * @covers phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::execute * @covers phpDocumentor\Compiler\Pass\NamespaceTreeBuilder::addElementsOfTypeToNamespace */ public function testAddTraitToNamespace() { $trait = new TraitDescriptor(); $trait->setNamespace('My\\Space'); $trait->setFullyQualifiedStructuralElementName('My\\Space\\Trait1'); $this->project->getFiles()->get(0)->getTraits()->add($trait); // double check if a second trait in the same deep namespace ends up at the right location $trait2 = new TraitDescriptor(); $trait2->setNamespace('My\\Space'); $trait2->setFullyQualifiedStructuralElementName('My\\Space\\Trait2'); $this->project->getFiles()->get(0)->getTraits()->add($trait2); $this->fixture->execute($this->project); $this->assertSame(array($trait, $trait2), $this->project->getNamespace()->getChildren()->get('My')->getChildren()->get('Space')->getTraits()->getAll()); }