/**
  * 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 #3
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;
 }