/** * @param \phpDocumentor\Reflection\BaseReflector $reflector * @param Context $context * @param array $config */ public function __construct($reflector = null, $context = null, $config = []) { parent::__construct($config); if ($reflector === null) { return; } // base properties $this->name = ltrim($reflector->getName(), '\\'); $this->startLine = $reflector->getNode()->getAttribute('startLine'); $this->endLine = $reflector->getNode()->getAttribute('endLine'); $docblock = $reflector->getDocBlock(); if ($docblock !== null) { $this->shortDescription = ucfirst($docblock->getShortDescription()); if (empty($this->shortDescription) && !$this instanceof PropertyDoc && $context !== null && $docblock->getTagsByName('inheritdoc') === null) { $context->errors[] = ['line' => $this->startLine, 'file' => $this->sourceFile, 'message' => "No short description for " . substr(StringHelper::basename(get_class($this)), 0, -3) . " '{$this->name}'"]; } $this->description = $docblock->getLongDescription()->getContents(); $this->phpDocContext = $docblock->getContext(); $this->tags = $docblock->getTags(); foreach ($this->tags as $i => $tag) { if ($tag instanceof SinceTag) { $this->since = $tag->getVersion(); unset($this->tags[$i]); } elseif ($tag instanceof DeprecatedTag) { $this->deprecatedSince = $tag->getVersion(); $this->deprecatedReason = $tag->getDescription(); unset($this->tags[$i]); } } } elseif ($context !== null) { $context->errors[] = ['line' => $this->startLine, 'file' => $this->sourceFile, 'message' => "No docblock for element '{$this->name}'"]; } }
/** * Validates whether the given Reflector's arguments match the business rules of phpDocumentor. * * @param BaseReflector $element * * @throws \UnexpectedValueException if no DocBlock is associated with the given Reflector. * * @return Error|null */ public function validate($element) { $docBlock = $element->getDocBlock(); if (null === $docBlock) { throw new \UnexpectedValueException('A DocBlock should be present (and validated) before this validator can be applied'); } if ($docBlock->hasTag('return')) { $returnTag = current($docBlock->getTagsByName('return')); if ($returnTag->getType() == 'type') { return new Error(LogLevel::WARNING, 'PPC:ERR-50017', $element->getLinenumber()); } } return null; }
/** * Exports the given reflection object to the parent XML element. * * This method creates a new child element on the given parent XML element * and takes the properties of the Reflection argument and sets the * elements and attributes on the child. * * If a child DOMElement is provided then the properties and attributes are * set on this but the child element is not appended onto the parent. This * is the responsibility of the invoker. Essentially this means that the * $parent argument is ignored in this case. * * @param \DOMElement $parent The parent element * to augment. * @param \phpDocumentor\Reflection\BaseReflector $element The data source. * * @return void */ public function export(\DOMElement $parent, $element) { $docblock = $element->getDocBlock(); if (!$docblock) { $parent->setAttribute('package', $element->getDefaultPackageName()); return; } $child = new \DOMElement('docblock'); $parent->appendChild($child); // TODO: custom attached member variable, make real $child->setAttribute('line', $docblock->line_number); $this->addDescription($child, $docblock); $this->addLongDescription($child, $docblock); $this->addTags($child, $docblock->getTags(), $element); $this->setParentsPackage($parent, $docblock, $element); }
/** * @param BaseReflector|ReflectionAbstract $element * * @return array */ function export_docblock($element) { $docblock = $element->getDocBlock(); if (!$docblock) { return array('description' => '', 'long_description' => '', 'tags' => array()); } $output = array('description' => preg_replace('/[\\n\\r]+/', ' ', $docblock->getShortDescription()), 'long_description' => preg_replace('/[\\n\\r]+/', ' ', $docblock->getLongDescription()->getFormattedContents()), 'tags' => array()); foreach ($docblock->getTags() as $tag) { $tag_data = array('name' => $tag->getName(), 'content' => preg_replace('/[\\n\\r]+/', ' ', format_description($tag->getDescription()))); if (method_exists($tag, 'getTypes')) { $tag_data['types'] = $tag->getTypes(); } if (method_exists($tag, 'getLink')) { $tag_data['link'] = $tag->getLink(); } if (method_exists($tag, 'getVariableName')) { $tag_data['variable'] = $tag->getVariableName(); } if (method_exists($tag, 'getReference')) { $tag_data['refers'] = $tag->getReference(); } if (method_exists($tag, 'getVersion')) { // Version string. $version = $tag->getVersion(); if (!empty($version)) { $tag_data['content'] = $version; } // Description string. if (method_exists($tag, 'getDescription')) { $description = preg_replace('/[\\n\\r]+/', ' ', format_description($tag->getDescription())); if (!empty($description)) { $tag_data['description'] = $description; } } } $output['tags'][] = $tag_data; } return $output; }