Ejemplo n.º 1
0
 /**
  * Creates a Descriptor from the provided data.
  *
  * @param FileReflector $data
  *
  * @return FileDescriptor
  */
 public function create($data)
 {
     $fileDescriptor = new FileDescriptor($data->getHash());
     $fileDescriptor->setPackage($this->extractPackageFromDocBlock($data->getDocBlock()) ?: $data->getDefaultPackageName());
     $packages = new Collection();
     $package = $this->extractPackageFromDocBlock($data->getDocBlock());
     if (!$package) {
         $package = $data->getDefaultPackageName();
     }
     $tag = new TagDescriptor('package');
     $tag->setDescription($package);
     $packages->add($tag);
     $fileDescriptor->getTags()->set('package', $packages);
     $fileDescriptor->setName(basename($data->getFilename()));
     $fileDescriptor->setPath($data->getFilename());
     $fileDescriptor->setSource($data->getContents());
     $fileDescriptor->setIncludes(new Collection($data->getIncludes()));
     $fileDescriptor->setNamespaceAliases(new Collection($data->getNamespaceAliases()));
     $this->assembleDocBlock($data->getDocBlock(), $fileDescriptor);
     $this->addMarkers($data->getMarkers(), $fileDescriptor);
     $this->addConstants($data->getConstants(), $fileDescriptor);
     $this->addFunctions($data->getFunctions(), $fileDescriptor);
     $this->addClasses($data->getClasses(), $fileDescriptor);
     $this->addInterfaces($data->getInterfaces(), $fileDescriptor);
     $this->addTraits($data->getTraits(), $fileDescriptor);
     return $fileDescriptor;
 }
 /**
  * Creates a Descriptor from the provided data.
  *
  * @param Collection $data
  *
  * @return DescriptorCollection
  */
 public function create($data)
 {
     $collection = new DescriptorCollection();
     foreach ($data as $type) {
         $collection->add($this->createDescriptorForType($type));
     }
     return $collection;
 }
Ejemplo n.º 3
0
 /**
  * Maps the properties of the Function reflector onto the Descriptor.
  *
  * @param FunctionReflector  $reflector
  * @param FunctionDescriptor $descriptor
  *
  * @return void
  */
 protected function mapReflectorPropertiesOntoDescriptor($reflector, $descriptor)
 {
     $packages = new Collection();
     $package = $this->extractPackageFromDocBlock($reflector->getDocBlock());
     if ($package) {
         $tag = new TagDescriptor('package');
         $tag->setDescription($package);
         $packages->add($tag);
     }
     $descriptor->getTags()->set('package', $packages);
     $descriptor->setFullyQualifiedStructuralElementName($reflector->getName() . '()');
     $descriptor->setName($reflector->getShortName());
     $descriptor->setLine($reflector->getLinenumber());
     $descriptor->setNamespace($this->getFullyQualifiedNamespaceName($reflector));
 }
Ejemplo n.º 4
0
 /**
  * @covers phpDocumentor\Descriptor\Collection::merge
  */
 public function testIfAfterMergeCollectionContainsAllItems()
 {
     $expected = array(0 => 'a', 1 => 'b', 2 => 'c');
     $this->fixture[1] = 'a';
     $this->fixture[2] = 'b';
     $collection2 = new Collection();
     $collection2[4] = 'c';
     $result = $this->fixture->merge($collection2);
     $this->assertSame($expected, $result->getAll());
 }
 /**
  * @covers phpDocumentor\Descriptor\DescriptorAbstract::getCopyright
  */
 public function testGetCopyRight()
 {
     $mock = m::mock('phpDocumentor\\Descriptor\\DescriptorAbstract, phpDocumentor\\Descriptor\\Interfaces\\ChildInterface');
     $mock->shouldDeferMissing();
     $copyright = new Collection(array('copyright'));
     $collection = new Collection();
     $collection->offsetSet('copyright', $copyright);
     $mock->shouldReceive('getTags')->andReturn($collection);
     $this->assertSame($copyright, $mock->getCopyright());
 }
 /**
  * Validates the contents of the Descriptor and outputs warnings and error if something is amiss.
  *
  * @param DescriptorAbstract $descriptor
  *
  * @return Collection
  */
 public function validate($descriptor)
 {
     $violations = $this->validator->validate($descriptor);
     $errors = new Collection();
     /** @var ConstraintViolation $violation */
     foreach ($violations as $violation) {
         $errors->add(new Error($this->mapCodeToSeverity($violation->getCode()), $violation->getMessageTemplate(), $descriptor->getLine(), $violation->getMessageParameters() + array($descriptor->getFullyQualifiedStructuralElementName())));
     }
     return $errors;
 }
Ejemplo n.º 7
0
 /**
  * @param $data
  * @param $fileDescriptor
  */
 protected function overridePackageTag($data, $fileDescriptor)
 {
     $packages = new Collection();
     $package = $this->extractPackageFromDocBlock($data->getDocBlock());
     if (!$package) {
         $package = $data->getDefaultPackageName();
     }
     $tag = new TagDescriptor('package');
     $tag->setDescription($package);
     $packages->add($tag);
     $fileDescriptor->getTags()->set('package', $packages);
 }
 /**
  * @covers phpDocumentor\Descriptor\InterfaceDescriptor::getInheritedMethods
  */
 public function testRetrievingInheritedMethodsReturnsCollectionWithParent()
 {
     $parentDescriptor = new MethodDescriptor();
     $parentDescriptor->setName('parent');
     $parentDescriptorCollection = new Collection();
     $parentDescriptorCollection->add($parentDescriptor);
     $parent = new InterfaceDescriptor();
     $parent->setMethods($parentDescriptorCollection);
     $parentCollection = new Collection();
     $parentCollection->add($parent);
     $grandParentDescriptor = new MethodDescriptor();
     $grandParentDescriptor->setName('grandparent');
     $grandParentDescriptorCollection = new Collection();
     $grandParentDescriptorCollection->add($grandParentDescriptor);
     $grandParent = new InterfaceDescriptor();
     $grandParent->setMethods($grandParentDescriptorCollection);
     $grandParentCollection = new Collection();
     $grandParentCollection->add($grandParent);
     $parent->setParent($grandParentCollection);
     $this->fixture->setParent($parentCollection);
     $result = $this->fixture->getInheritedMethods();
     $this->assertInstanceOf('phpDocumentor\\Descriptor\\Collection', $result);
     $this->assertSame(array($parentDescriptor, $grandParentDescriptor), $result->getAll());
 }