/**
  * Generates a URL from the given node or returns false if unable.
  *
  * @param string|Descriptor\MethodDescriptor $node
  *
  * @return string|false
  */
 public function __invoke($node)
 {
     if (!$node instanceof Descriptor\MethodDescriptor) {
         return false;
     }
     $converter = new QualifiedNameToUrlConverter();
     $className = $node->getParent()->getFullyQualifiedStructuralElementName();
     return '/classes/' . $converter->fromClass($className) . '.html#method_' . $node->getName();
 }
 /**
  * @covers phpDocumentor\Descriptor\MethodDescriptor::getResponse
  */
 public function testRetrieveReturnTagForResponse()
 {
     $mock = new \stdClass();
     $this->assertNull($this->fixture->getResponse());
     $this->fixture->getTags()->set('return', new Collection(array($mock)));
     $this->assertSame($mock, $this->fixture->getResponse());
 }
 /**
  * @param string $name The name of the current method.
  *
  * @return MethodDescriptor
  */
 protected function whenFixtureHasMethodInImplementedInterfaceWithSameName($name)
 {
     $result = new MethodDescriptor();
     $result->setName($name);
     $parent = new InterfaceDescriptor();
     $parent->getMethods()->set($name, $result);
     $class = new ClassDescriptor();
     $class->getInterfaces()->set('Implemented', $parent);
     $this->fixture->setParent($class);
     return $result;
 }
 /**
  * Creates a Descriptor from the provided data.
  *
  * @param MethodReflector $data
  *
  * @return MethodDescriptor
  */
 public function create($data)
 {
     $methodDescriptor = new MethodDescriptor();
     $methodDescriptor->setFullyQualifiedStructuralElementName($data->getName() . '()');
     $methodDescriptor->setName($data->getShortName());
     $methodDescriptor->setVisibility($data->getVisibility() ?: 'public');
     $methodDescriptor->setFinal($data->isFinal());
     $methodDescriptor->setAbstract($data->isAbstract());
     $methodDescriptor->setStatic($data->isStatic());
     $this->assembleDocBlock($data->getDocBlock(), $methodDescriptor);
     foreach ($data->getArguments() as $argument) {
         $argumentAssembler = new ArgumentAssembler();
         $argumentDescriptor = $argumentAssembler->create($argument, $methodDescriptor->getTags()->get('param', array()));
         $methodDescriptor->getArguments()->set($argumentDescriptor->getName(), $argumentDescriptor);
     }
     $methodDescriptor->setLine($data->getLinenumber());
     return $methodDescriptor;
 }
 /**
  * Export the given reflected method definition to the provided parent element.
  *
  * @param \DOMElement      $parent Element to augment.
  * @param MethodDescriptor $method Element to export.
  *
  * @return \DOMElement
  */
 public function convert(\DOMElement $parent, MethodDescriptor $method)
 {
     $fullyQualifiedNamespaceName = $method->getNamespace() instanceof NamespaceDescriptor ? $method->getNamespace()->getFullyQualifiedStructuralElementName() : $parent->getAttribute('namespace');
     $child = new \DOMElement('method');
     $parent->appendChild($child);
     $child->setAttribute('final', var_export($method->isFinal(), true));
     $child->setAttribute('abstract', var_export($method->isAbstract(), true));
     $child->setAttribute('static', var_export($method->isStatic(), true));
     $child->setAttribute('visibility', $method->getVisibility());
     $child->setAttribute('namespace', $fullyQualifiedNamespaceName);
     $child->setAttribute('line', $method->getLine());
     $child->appendChild(new \DOMElement('name', $method->getName()));
     $child->appendChild(new \DOMElement('full_name', $method->getFullyQualifiedStructuralElementName()));
     $this->docBlockConverter->convert($child, $method);
     foreach ($method->getArguments() as $argument) {
         $this->argumentConverter->convert($child, $argument);
     }
     return $child;
 }
 /**
  * Checks if there is a variadic argument in the `@param` tags and adds it to the list of Arguments in
  * the Descriptor unless there is already one present.
  *
  * @param MethodReflector  $data
  * @param MethodDescriptor $methodDescriptor
  *
  * @return void
  */
 protected function addVariadicArgument($data, $methodDescriptor)
 {
     if (!$data->getDocBlock()) {
         return;
     }
     $paramTags = $data->getDocBlock()->getTagsByName('param');
     /** @var ParamTag $lastParamTag */
     $lastParamTag = end($paramTags);
     if (!$lastParamTag) {
         return;
     }
     if ($lastParamTag->isVariadic() && !in_array($lastParamTag->getVariableName(), array_keys($methodDescriptor->getArguments()->getAll()))) {
         $types = $this->builder->buildDescriptor(new Collection($lastParamTag->getTypes()));
         $argument = new ArgumentDescriptor();
         $argument->setName($lastParamTag->getVariableName());
         $argument->setTypes($types);
         $argument->setDescription($lastParamTag->getDescription());
         $argument->setLine($methodDescriptor->getLine());
         $argument->setVariadic(true);
         $methodDescriptor->getArguments()->set($argument->getName(), $argument);
     }
 }
Example #7
0
 /**
  * Export the given reflected method definition to the provided parent element.
  *
  * @param \DOMElement     $parent Element to augment.
  * @param MethodDescriptor $method Element to export.
  *
  * @return \DOMElement
  */
 public function buildMethod(\DOMElement $parent, MethodDescriptor $method)
 {
     $child = new \DOMElement('method');
     $parent->appendChild($child);
     $child->setAttribute('final', $method->isFinal() ? 'true' : 'false');
     $child->setAttribute('abstract', $method->isAbstract() ? 'true' : 'false');
     $child->setAttribute('static', $method->isStatic() ? 'true' : 'false');
     $child->setAttribute('visibility', $method->getVisibility());
     $namespaceFqnn = $method->getNamespace() ? $method->getNamespace()->getFullyQualifiedStructuralElementName() : $parent->getAttribute('namespace');
     $child->setAttribute('namespace', $namespaceFqnn);
     $child->setAttribute('line', $method->getLine());
     $child->appendChild(new \DOMElement('name', $method->getName()));
     $child->appendChild(new \DOMElement('full_name', $method->getFullyQualifiedStructuralElementName()));
     $this->buildDocBlock($child, $method);
     foreach ($method->getArguments() as $argument) {
         $this->buildArgument($child, $argument);
     }
     return $child;
 }
 /**
  * Returns a method whose name is set.
  *
  * @param ClassDescriptor $classDescriptor
  * @param string          $methodName
  *
  * @return MethodDescriptor
  */
 private function givenAMethodWithClassAndName(ClassDescriptor $classDescriptor, $methodName)
 {
     $methodDescriptor = new MethodDescriptor();
     $methodDescriptor->setName($methodName);
     $methodDescriptor->setFullyQualifiedStructuralElementName($classDescriptor . '::' . $methodName . '()');
     return $methodDescriptor;
 }
 /**
  * @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());
 }
 /**
  * Generates a URL from the given node or returns false if unable.
  *
  * @param \phpDocumentor\Descriptor\MethodDescriptor $node
  *
  * @return string|false
  */
 public function __invoke($node)
 {
     $className = $node->getParent()->getFullyQualifiedStructuralElementName();
     $name = $node->getName();
     return '/classes/' . str_replace('\\', '.', ltrim($className, '\\')) . '.html#property_' . $name;
 }
 /**
  * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::execute
  * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::addElementsToIndexes
  * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getIndexKey
  * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getSubElements
  */
 public function testAddMethodsToIndex()
 {
     $file1 = $this->project->getFiles()->get(0);
     $classDescriptor1 = new ClassDescriptor();
     $classDescriptor1->setFullyQualifiedStructuralElementName('My\\Space\\Class1');
     $file1->getClasses()->add($classDescriptor1);
     $classMethodDescriptor1 = new MethodDescriptor();
     $classMethodDescriptor1->setFullyQualifiedStructuralElementName('My\\Space\\Class1::METHOD');
     $classDescriptor1->getMethods()->add($classMethodDescriptor1);
     $file2 = $this->project->getFiles()->get(1);
     $classDescriptor2 = new ClassDescriptor();
     $classDescriptor2->setFullyQualifiedStructuralElementName('My\\Space\\Class2');
     $file2->getClasses()->add($classDescriptor2);
     $classMethodDescriptor2 = new MethodDescriptor();
     $classMethodDescriptor2->setFullyQualifiedStructuralElementName('My\\Space\\Class2::METHOD');
     $classDescriptor2->getMethods()->add($classMethodDescriptor2);
     $this->fixture->execute($this->project);
     $elements = $this->project->getIndexes()->get('elements')->getAll();
     $this->assertCount(4, $elements);
     $this->assertSame(array('My\\Space\\Class1', 'My\\Space\\Class1::METHOD', 'My\\Space\\Class2', 'My\\Space\\Class2::METHOD'), array_keys($elements));
     $this->assertSame(array($classDescriptor1, $classMethodDescriptor1, $classDescriptor2, $classMethodDescriptor2), array_values($elements));
     // class methods are not indexed separately
     $this->assertNull($this->project->getIndexes()->get('methods'));
 }