/**
  * Creates a Descriptor from the provided data.
  *
  * @param ClassReflector $data
  *
  * @return ClassDescriptor
  */
 public function create($data)
 {
     $classDescriptor = new ClassDescriptor();
     $classDescriptor->setFullyQualifiedStructuralElementName($data->getName());
     $classDescriptor->setName($data->getShortName());
     $classDescriptor->setPackage($this->extractPackageFromDocBlock($data->getDocBlock()) ?: '');
     $classDescriptor->setLine($data->getLinenumber());
     $classDescriptor->setParent($data->getParentClass());
     $classDescriptor->setAbstract($data->isAbstract());
     $classDescriptor->setFinal($data->isFinal());
     // Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself
     $classDescriptor->setNamespace('\\' . (strtolower($data->getNamespace()) == 'global' ? '' : $data->getNamespace()));
     foreach ($data->getInterfaces() as $interfaceClassName) {
         $classDescriptor->getInterfaces()->set($interfaceClassName, $interfaceClassName);
     }
     $fqcn = $classDescriptor->getFullyQualifiedStructuralElementName();
     $namespace = substr($fqcn, 0, strrpos($fqcn, '\\'));
     $classDescriptor->setNamespace($namespace);
     $this->assembleDocBlock($data->getDocBlock(), $classDescriptor);
     $this->addConstants($data->getConstants(), $classDescriptor);
     $this->addProperties($data->getProperties(), $classDescriptor);
     $this->addMethods($data->getMethods(), $classDescriptor);
     $this->addUses($data->getTraits(), $classDescriptor);
     return $classDescriptor;
 }
 /**
  * @covers phpDocumentor\Compiler\Pass\PackageTreeBuilder::execute
  * @covers phpDocumentor\Compiler\Pass\PackageTreeBuilder::addElementsOfTypeToPackage
  */
 public function testAddClassToNamespace()
 {
     $class = new ClassDescriptor();
     $class->setPackage('My\\Space');
     $class->setFullyQualifiedStructuralElementName('My\\Space\\Class1');
     $this->project->getFiles()->get(0)->getClasses()->add($class);
     // double check if a second class in the same deep namespace ends up at the right location
     $class2 = new ClassDescriptor();
     $class2->setPackage('My\\Space');
     $class2->setFullyQualifiedStructuralElementName('My\\Space\\Class2');
     $this->project->getFiles()->get(0)->getClasses()->add($class2);
     $this->fixture->execute($this->project);
     $this->assertSame(array($class, $class2), $this->project->getIndexes()->get('packages')->get('\\My\\Space')->getClasses()->getAll());
 }