Example #1
0
 public function parse(Class_ $node, Entity\FQN $fqn, $file)
 {
     $fqcn = new Entity\FQCN($node->name, $fqn);
     $classData = new Node\ClassData($fqcn, $file);
     if ($node->extends instanceof Name) {
         $classData->setParent($this->useParser->getFQCN($node->extends));
     }
     foreach ($node->implements as $interfaceName) {
         $classData->addInterface($this->useParser->getFQCN($interfaceName));
     }
     $classData->startLine = $node->getAttribute("startLine");
     $this->parseDocComments($classData, $node->getAttribute("comments"));
     foreach ($node->stmts as $child) {
         if ($child instanceof ClassMethod) {
             $classData->addMethod($this->parseMethod($child));
         } elseif ($child instanceof Property) {
             foreach ($child->props as $prop) {
                 $classData->addProp($this->parseProperty($prop, $child->type, $child->getAttribute('comments')));
             }
         } elseif ($child instanceof ClassConst) {
             foreach ($child->consts as $const) {
                 $classData->addConst($const->name);
             }
         }
     }
     return $classData;
 }
 public function store_class(Node\Stmt\Class_ $class)
 {
     if ($class->extends) {
         $parent = end($class->extends->parts);
         $parent_namespace = implode('\\', array_slice($class->extends->parts, 0, -1));
     } else {
         $parent = '';
         $parent_namespace = '';
     }
     $description = '';
     if ($comments = $class->getAttribute('comments')) {
         $phpdoc = new DocBlock($comments[0]->getText());
         $description = $phpdoc->getShortDescription();
         // short circuit @ignore functions
         if ($phpdoc->hasTag('ignore')) {
             return;
         }
     }
     $this->store_model('classes', array('class' => $class->name, 'namespace' => !empty($class->namespacedName) ? implode('\\', array_slice($class->namespacedName->parts, 0, -1)) : '', 'file' => $this->_current_file, 'line' => $class->getLine(), 'parent' => $parent, 'parent_namespace' => $parent_namespace, 'description' => $description));
     $methods = array_filter($class->stmts, function ($node) {
         return $node instanceof Node\Stmt\ClassMethod;
     });
     foreach ($methods as $method) {
         $this->store_class_method($class, $method);
     }
     $constants = array_filter($class->stmts, function ($node) {
         return $node instanceof Node\Stmt\ClassConst;
     });
     foreach ($constants as $constant) {
         $this->store_class_constant($class, $constant);
     }
 }
 /**
  * Find the last/nearest PHPDOC of the class.
  * @param Class_ $class
  * @return null|Doc
  */
 private static function getLastPhpDocComment(Class_ $class)
 {
     $comments = $class->getAttribute('comments');
     if (NULL === $comments) {
         return NULL;
     }
     $lastPhpdocComment = NULL;
     foreach ($comments as $comment) {
         if ($comment instanceof Doc) {
             $lastPhpdocComment = $comment;
         }
     }
     return $lastPhpdocComment;
 }