Example #1
0
 /**
  * @param ClassMethod $node
  *
  * @return RefMethod
  */
 private function createMethod(ClassMethod $node)
 {
     $ref = new RefMethod();
     $ref->class = $this->class;
     $ref->name = $node->name;
     if ($node->isPrivate()) {
         $ref->visibility = Visibility::IS_PRIVATE;
     } elseif ($node->isProtected()) {
         $ref->visibility = Visibility::IS_PROTECTED;
     } elseif ($node->isPublic()) {
         $ref->visibility = Visibility::IS_PUBLIC;
     }
     $ref->isStatic = $node->isStatic();
     $ref->isAbstract = $node->isAbstract();
     $ref->isFinal = $node->isFinal();
     $ref->startLine = $node->getLine();
     $ref->docComment = $this->createDocComment($node);
     $ref->returnType = $this->getTypeName($node->getReturnType());
     foreach ($node->getParams() as $param) {
         $param = $this->createParam($param, $ref->docComment);
         $ref->params[$param->name] = $param;
     }
     return $ref;
 }
 /**
  * @param Node\Stmt\ClassMethod $node
  */
 protected function parseClassMethodNode(Node\Stmt\ClassMethod $node)
 {
     $parameters = [];
     /** @var \PhpParser\Node\Param $param */
     foreach ($node->params as $param) {
         $parameters[] = ['name' => $param->name, 'type' => (string) $param->type, 'isReference' => $param->byRef, 'isVariadic' => $param->variadic, 'isOptional' => $param->default ? true : false];
     }
     $this->structuralElements[$this->currentStructuralElement->namespacedName->toString()]['methods'][] = ['name' => $node->name, 'startLine' => $node->getLine(), 'isPublic' => $node->isPublic(), 'isPrivate' => $node->isPrivate(), 'isProtected' => $node->isProtected(), 'isStatic' => $node->isStatic(), 'returnType' => $node->getReturnType(), 'parameters' => $parameters, 'docComment' => $node->getDocComment() ? $node->getDocComment()->getText() : null];
 }
 /**
  * @return int
  */
 public function getLine()
 {
     return $this->classMethodBefore->getLine();
 }
 /**
  * @return int
  */
 public function getLine()
 {
     return $this->classMethodAfter->getLine();
 }
Example #5
0
 protected function addMethod(ClassMethodNode $node)
 {
     $method = new MethodReflection($node->name, $node->getLine());
     $method->setModifiers((string) $node->type);
     $method->setByRef((string) $node->byRef);
     foreach ($node->params as $param) {
         $parameter = new ParameterReflection($param->name, $param->getLine());
         $parameter->setModifiers((string) $param->type);
         $parameter->setByRef($param->byRef);
         if ($param->default) {
             $parameter->setDefault($this->context->getPrettyPrinter()->prettyPrintExpr($param->default));
         }
         if ((string) $param->type) {
             $parameter->setHint($this->resolveHint(array(array((string) $param->type, false))));
         }
         $method->addParameter($parameter);
     }
     $comment = $this->context->getDocBlockParser()->parse($node->getDocComment(), $this->context, $method);
     $method->setDocComment($node->getDocComment());
     $method->setShortDesc($comment->getShortDesc());
     $method->setLongDesc($comment->getLongDesc());
     if (!($errors = $comment->getErrors())) {
         $errors = $this->updateMethodParametersFromTags($method, $comment->getTag('param'));
         if ($tag = $comment->getTag('return')) {
             $method->setHint($this->resolveHint($tag[0][0]));
             $method->setHintDesc($tag[0][1]);
         }
         $method->setExceptions($comment->getTag('throws'));
         $method->setTags($comment->getOtherTags());
     }
     $method->setErrors($errors);
     if ($this->context->getFilter()->acceptMethod($method)) {
         $this->context->getClass()->addMethod($method);
         if ($errors) {
             $this->context->addErrors((string) $method, $node->getLine(), $errors);
         }
     }
 }
 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));
 }