/** * Returns the parsed DocBlock. * * @return \phpDocumentor\Reflection\DocBlock|null */ public function getDocBlock() { $doc_block = null; $comment = $this->constant->getDocComment(); if ($comment) { try { $doc_block = new \phpDocumentor\Reflection\DocBlock((string) $comment, $this->getNamespace(), $this->getNamespaceAliases()); $doc_block->line_number = $comment->getLine(); } catch (\Exception $e) { $this->log($e->getMessage(), 2); } } \phpDocumentor\Plugin\EventDispatcher::getInstance()->dispatch('reflection.docblock-extraction.post', \phpDocumentor\Reflection\Events\PostDocBlockExtractionEvent::createInstance($this)->setDocblock($doc_block)); return $doc_block; }
/** * Checks all phpDocumentor whether they match the given rules. * * @param \phpDocumentor\Reflection\Events\PostDocBlockExtractionEvent $data * Event object containing the parameters. * * @phpdoc-event reflection.docblock-extraction.post * * @return void */ public function validateDocBlocks($data) { /** @var \phpDocumentor\Reflection\BaseReflector $element */ $element = $data->getSubject(); /** @var \phpDocumentor\Reflection\DocBlock $docblock */ $docblock = $data->getDocblock(); // get the type of element $type = substr(get_class($element), strrpos(get_class($element), '\\') + 1, -9); // no docblock, or docblock should be ignored, so no reason to validate if ($docblock && $docblock->hasTag('ignore')) { return; } $validatorOptions = $this->loadConfiguration(); foreach (array('Deprecated', 'Required', $type) as $validator) { // todo: move to a factory or builder class $class = 'phpDocumentor\\Plugin\\Core\\Parser\\DocBlock\\Validator\\' . $validator . 'Validator'; if (class_exists($class)) { /** @var Parser\DocBlock\Validator\ValidatorAbstract $val */ $val = new $class($this->plugin, $element->getName(), $docblock, $element); $val->setOptions($validatorOptions); $val->isValid(); } } }
public function beforeTraverse(array $nodes) { $node = null; $key = 0; foreach ($nodes as $k => $n) { if (!$n instanceof \PHPParser_Node_Stmt_InlineHTML) { $node = $n; $key = $k; break; } } if ($node) { $comments = (array) $node->getAttribute('comments'); // remove non-DocBlock comments $comments = array_values(array_filter($comments, function ($comment) { return $comment instanceof \PHPParser_Comment_Doc; })); if (!empty($comments)) { $docblock = new \phpDocumentor\Reflection\DocBlock((string) $comments[0]); // the first DocBlock in a file documents the file if // * it precedes another DocBlock or // * it contains a @package tag and doesn't precede a class // declaration or // * it precedes a non-documentable element (thus no include, // require, class, function, define, const) if (count($comments) > 1 || !$node instanceof \PHPParser_Node_Stmt_Class && $docblock->hasTag('package') || !$this->isNodeDocumentable($node)) { $docblock->line_number = $comments[0]->getLine(); $this->doc_block = $docblock; // remove the file level DocBlock from the node's comments $comments = array_slice($comments, 1); } } // always update the comments attribute so that standard comments // do not stop DocBlock from being attached to an element $node->setAttribute('comments', $comments); $nodes[$key] = $node; } \phpDocumentor\Plugin\EventDispatcher::getInstance()->dispatch('reflection.docblock-extraction.post', \phpDocumentor\Reflection\Events\PostDocBlockExtractionEvent::createInstance($this)->setDocblock($this->doc_block)); return $nodes; }