示例#1
0
 /**
  * Parses ClassMethod node to MethodData
  *
  * @return MethodData
  */
 public function parse(ClassMethod $node)
 {
     $method = new MethodData($node->name);
     $method->startLine = $node->getAttribute("startLine");
     $method->endLine = $node->getAttribute("endLine");
     $method->setType($node->type);
     $comments = $node->getAttribute("comments");
     if (is_array($comments)) {
         /** @var Comment */
         $comment = $this->commentParser->parse($comments[count($comments) - 1]->getText());
         if ($comment->isInheritDoc()) {
             $method->doc = Comment::INHERIT_MARK;
         } else {
             $method->doc = $comment->getDoc();
             $method->return = $comment->getReturn();
             foreach ($comment->getVars() as $var) {
                 if ($var instanceof MethodParam) {
                     $method->addParam($var);
                 }
             }
         }
     }
     foreach ($node->params as $child) {
         if ($child instanceof Param) {
             $method->addParam($this->parseMethodArgument($child));
         }
     }
     return $method;
 }
        /**
         * @param \PhpParser\Node\Stmt\ClassMethod $node
         */
        private function processMethod(\PhpParser\Node\Stmt\ClassMethod $node) {

            /** @var $method \TheSeer\phpDox\Collector\MethodObject */
            $method = $this->unit->addMethod($node->name);
            $method->setStartLine($node->getAttribute('startLine'));
            $method->setEndLine($node->getAttribute('endLine'));
            $method->setAbstract($node->isAbstract());
            $method->setFinal($node->isFinal());
            $method->setStatic($node->isStatic());

            $visibility = 'public';
            if ($node->isPrivate()) {
                $visibility = 'private';
            } elseif ($node->isProtected()) {
                $visibility = 'protected';
            }
            $method->setVisibility($visibility);
            $docComment = $node->getDocComment();
            if ($docComment !== NULL) {
                $block = $this->dockblocParser->parse($docComment, $this->aliasMap);
                $method->setDocBlock($block);
            }
            $this->processMethodParams($method, $node->params);
            if ($node->stmts) {
                $this->processInlineComments($method, $node->stmts);
            }
        }
示例#3
0
 public function pStmt_ClassMethod(Stmt\ClassMethod $node)
 {
     $firstToken = '';
     $lastToken = '';
     if (count($node->params) > 0) {
         if ($node->getAttribute('startLine') != reset($node->params)->getAttribute('startLine')) {
             $firstToken = LF . $this->indentToken;
         }
         // if the last parameters endline is 2 lines above the first statements
         // startLine, the closing bracket is in a new line (except if there is a comment)
         if ($this->getFirstLineOfMethodBody($node->stmts) - end($node->params)->getAttribute('endLine') > 1) {
             $lastToken = LF;
         }
     }
     return $this->pModifiers($node->type) . 'function ' . ($node->byRef ? '&' : '') . $node->name . '(' . $firstToken . $this->pParameterNodes($node->params) . $lastToken . ')' . (NULL !== $node->stmts ? ' {' . LF . $this->pStmts($node->stmts) . LF . '}' . LF : ';');
 }
 /**
  * Get the line number that this function ends on.
  *
  * @return int
  */
 public function getEndLine()
 {
     return (int) $this->node->getAttribute('endLine', -1);
 }
 public function addMethod(ClassMethodNode $node)
 {
     $method = new ReflectionMethod($node->name);
     $method->setStartLine((int) $node->getAttribute('startLine'));
     $method->setEndLine((int) $node->getAttribute('endLine'));
     $method->setDocComment((string) $node->getDocComment());
     $method->setReturnsByRef((bool) $node->returnsByRef());
     $method->setFinal((bool) $node->isFinal());
     $method->setStatic((bool) $node->isStatic());
     $this->addFunctionLikeParameters($method, $node->params);
     // All functions in an interface are implicitly abstract. There is no need to use the abstract keyword when declaring the function.
     if ($this->context->getReflection() instanceof ReflectionInterface) {
         $method->setAbstract(true);
     } else {
         $method->setAbstract((bool) $node->isAbstract());
     }
     if ($node->isPrivate()) {
         $method->setVisibility(ReflectionMethod::IS_PRIVATE);
     } elseif ($node->isProtected()) {
         $method->setVisibility(ReflectionMethod::IS_PROTECTED);
     } else {
         $method->setVisibility(ReflectionMethod::IS_PUBLIC);
     }
     $this->context->getReflection()->addMethod($method);
     $this->context->enterFunctionLike($method);
 }
 public function store_class_method(Node\Stmt\Class_ $class, Node\Stmt\ClassMethod $method)
 {
     $parameters = array_map(function ($param) {
         return array('name' => $param->name, 'default' => !empty($param->default), 'type' => ltrim((string) $param->type, '\\'));
     }, $method->getParams());
     $access = array_keys(array_filter(array('public' => $method->isPublic(), 'protected' => $method->isProtected(), 'private' => $method->isPrivate())))[0];
     $return_types = array();
     $description = '';
     if ($comments = $method->getAttribute('comments')) {
         $phpdoc = new DocBlock($comments[0]->getText());
         $description = $phpdoc->getShortDescription();
         if ($return = $phpdoc->getTagsByName('return')) {
             $return_types = array_map('ltrim', explode('|', $return[0]->getType()), array('\\'));
         }
         // short circuit @ignore functions
         if ($phpdoc->hasTag('ignore')) {
             return;
         }
     }
     $this->store_model('methods', array('method' => $method->name, 'namespace' => !empty($method->namespacedName) ? implode('\\', array_slice($method->namespacedName->parts, 0, -1)) : '', 'file' => $this->_current_file, 'line' => $method->getLine(), 'description' => $description, 'return_types' => json_encode($return_types), 'parameters' => json_encode($parameters), 'access' => $access, 'is_static' => $method->isStatic(), 'class' => $class->name));
 }