/** * 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; }
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); } } }