/**
  * 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;
 }
示例#2
0
 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;
 }