/**
  * Adds a new method to the class using an array of tokens
  *
  * @param ClassReflection $class     Class reflection
  * @param string          $methodTag Method tag contents
  *
  * @return bool
  */
 protected function injectMethod(ClassReflection $class, $methodTag)
 {
     $data = $this->parseMethod($methodTag);
     // Bail if the method format is invalid
     if (!$data) {
         return false;
     }
     $method = new MethodReflection($data['name'], $class->getLine());
     $method->setDocComment($data['description']);
     $method->setShortDesc($data['description']);
     if ($data['hint']) {
         $method->setHint(array(array($data['hint'], null)));
     }
     // Add arguments to the method
     foreach ($data['args'] as $name => $arg) {
         $param = new ParameterReflection($name, $class->getLine());
         if (!empty($arg['hint'])) {
             $param->setHint(array(array($arg['hint'], null)));
         }
         if (!empty($arg['default'])) {
             $param->setDefault($arg['default']);
         }
         $method->addParameter($param);
     }
     $class->addMethod($method);
     return true;
 }
Ejemplo n.º 2
0
 protected function addMethod(\PHPParser_Node_Stmt_ClassMethod $node)
 {
     $method = new MethodReflection($node->name, $node->getLine());
     $method->setModifiers((string) $node->type);
     if ($this->context->getFilter()->acceptMethod($method)) {
         $this->context->getClass()->addMethod($method);
         $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());
         }
         $this->context->addErrors((string) $method, $node->getLine(), $errors);
     }
 }
Ejemplo n.º 3
0
 public static function fromArray(Project $project, $array)
 {
     $method = new self($array['name'], $array['line']);
     $method->shortDesc = $array['short_desc'];
     $method->longDesc = $array['long_desc'];
     $method->hint = $array['hint'];
     $method->hintDesc = $array['hint_desc'];
     $method->tags = $array['tags'];
     $method->modifiers = $array['modifiers'];
     $method->byRef = $array['is_by_ref'];
     $method->exceptions = $array['exceptions'];
     $method->errors = $array['errors'];
     foreach ($array['parameters'] as $parameter) {
         $parameter = ParameterReflection::fromArray($project, $parameter);
         $method->addParameter($parameter);
     }
     return $method;
 }
 public function addParameter(ParameterReflection $parameter)
 {
     $this->parameters[$parameter->getName()] = $parameter;
     $parameter->setMethod($this);
 }