Exemple #1
0
 /**
  * @param Function_                       $function
  * @param Stmt\Function_|Stmt\ClassMethod $node
  */
 protected function processFunction(Function_ $function, $node)
 {
     $this->init($function, $node);
     $function->setReturnByRef($node->byRef);
     $function->setReturnType($this->getType($node->returnType));
     $annotations = [];
     if ($node->hasAttribute('annotations')) {
         $annotations = $node->getAttribute('annotations');
     }
     $docReturnType = Type::mixed_();
     if (!empty($annotations['return'])) {
         $docReturnType = $annotations['return'][count($annotations['return']) - 1]->getType();
     }
     $function->setDocReturnType($docReturnType);
     $paramDocTypes = [];
     if (!empty($annotations['param'])) {
         foreach ($annotations['param'] as $paramTag) {
             $paramDocTypes[$paramTag->getIdentifier()] = $paramTag->getType();
         }
     }
     foreach ($node->params as $paramNode) {
         $param = new Param();
         $param->setName('$' . $paramNode->name);
         $param->setByRef($paramNode->byRef);
         $param->setOptional($paramNode->default !== null);
         $param->setVariadic($paramNode->variadic);
         $param->setTypeHint($this->getType($paramNode->type));
         $param->setDocType(empty($paramDocTypes[$param->getName()]) ? Type::mixed_() : $paramDocTypes[$param->getName()]);
         // TODO: variadic parameter type hints?
         $function->addParam($param);
     }
 }
Exemple #2
0
 protected function handleFunction(Function_ $function, array $data)
 {
     $this->handleElement($function, $data);
     $function->setReturnType(Type::mixed_());
     $function->setDocReturnType($this->getType($data['return_type']));
     $function->setReturnByRef($data['return_by_ref']);
     foreach ($data['params'] as $paramData) {
         $param = new Param();
         $param->setName($paramData['name']);
         $param->setTypeHint(Type::mixed_());
         $param->setDocType($this->getType($paramData['type']));
         $param->setOptional($paramData['optional']);
         $param->setByRef($paramData['by_ref']);
         $param->setVariadic($paramData['variadic']);
         $function->addParam($param);
     }
 }