/**
  * Checks all phpDocumentor whether they match the given rules.
  *
  * @param PostDocBlockExtractionEvent $data Event object containing the parameters.
  *
  * @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 ValidatorAbstract $val */
             $val = new $class($element->getName(), $docblock, $element);
             $val->setOptions($validatorOptions);
             $val->isValid();
         }
     }
 }
 /**
  * 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\Event\Dispatcher::getInstance()->dispatch('reflection.docblock-extraction.post', \phpDocumentor\Reflection\Event\PostDocBlockExtractionEvent::createInstance($this)->setDocblock($doc_block));
     return $doc_block;
 }
Exemple #3
0
 /**
  * Extracts a parsed DocBlock from an object.
  *
  * @param object $node Any object with a "getDocComment()" method.
  *
  * @return DocBlock|null
  */
 protected function extractDocBlock($node)
 {
     $doc_block = null;
     $comment = $node->getDocComment();
     if ($comment) {
         try {
             $doc_block = new DocBlock((string) $comment, $this->context, new Location($comment->getLine()));
         } catch (Exception $e) {
             $this->log($e->getMessage(), LogLevel::CRITICAL);
         }
     }
     if (class_exists('phpDocumentor\\Event\\Dispatcher')) {
         Dispatcher::getInstance()->dispatch('reflection.docblock-extraction.post', PostDocBlockExtractionEvent::createInstance($this)->setDocblock($doc_block));
     }
     return $doc_block;
 }
 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 && !$node instanceof \PHPParser_Node_Stmt_Interface && $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\Event\Dispatcher::getInstance()->dispatch('reflection.docblock-extraction.post', \phpDocumentor\Reflection\Event\PostDocBlockExtractionEvent::createInstance($this)->setDocblock($this->doc_block));
     return $nodes;
 }
 /**
  * Extracts a parsed DocBlock from an object.
  * 
  * @param object $node Any object with a "getDocComment()" method.
  * 
  * @return DocBlock|null
  */
 protected function extractDocBlock($node)
 {
     $doc_block = null;
     $comment = $node->getDocComment();
     if ($comment) {
         try {
             $doc_block = new DocBlock((string) $comment, $this->context, new Location($comment->getLine()));
         } catch (Exception $e) {
             $this->log($e->getMessage(), 2);
         }
     }
     Dispatcher::getInstance()->dispatch('reflection.docblock-extraction.post', PostDocBlockExtractionEvent::createInstance($this)->setDocblock($doc_block));
     return $doc_block;
 }
 public function beforeTraverse(array $nodes)
 {
     $node = null;
     $key = 0;
     foreach ($nodes as $k => $n) {
         if (!$n instanceof 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 Doc;
         }));
         if (!empty($comments)) {
             try {
                 $docblock = new DocBlock((string) $comments[0], null, new Location($comments[0]->getLine()));
                 // 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 Class_ && !$node instanceof Interface_ && $docblock->hasTag('package') || !$this->isNodeDocumentable($node)) {
                     $this->doc_block = $docblock;
                     // remove the file level DocBlock from the node's comments
                     array_shift($comments);
                 }
             } catch (\Exception $e) {
                 $this->log($e->getMessage(), LogLevel::CRITICAL);
             }
         }
         // 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;
     }
     if (class_exists('phpDocumentor\\Event\\Dispatcher')) {
         Dispatcher::getInstance()->dispatch('reflection.docblock-extraction.post', PostDocBlockExtractionEvent::createInstance($this)->setDocblock($this->doc_block));
     }
     return $nodes;
 }