Esempio n. 1
0
 /**
  * @param \PhpParser\Node\Stmt $node
  * @param \EBT\ExtensionBuilder\Domain\Model\FunctionObject $object
  * @return \EBT\ExtensionBuilder\Domain\Model\AbstractObject
  */
 protected function setFunctionProperties(\PhpParser\Node\Stmt $node, Model\FunctionObject $object)
 {
     if (property_exists($node, 'type')) {
         $object->setModifiers($node->type);
     }
     $object->setBodyStmts($node->stmts);
     $position = 0;
     $object->setStartLine($node->getAttribute('startLine'));
     $object->setEndLine($node->getAttribute('endLine'));
     $getVarTypeFromParamTag = false;
     $paramTags = array();
     if ($object->isTaggedWith('param') && is_array($object->getTagValues('param'))) {
         $paramTags = $object->getTagValues('param');
         if (count($paramTags) == count($node->params)) {
             $getVarTypeFromParamTag = true;
         }
     }
     /** @var $param \PhpParser\NodeAbstract */
     foreach ($node->params as $param) {
         $parameter = new Model\ClassObject\MethodParameter($param->name);
         $parameter->setPosition($position);
         $parameter->setStartLine($param->getAttribute('startLine'));
         $parameter->setEndLine($param->getAttribute('endLine'));
         if (!is_null($param->type)) {
             $parameter->setTypeHint(NodeConverter::getValueFromNode($param->type));
             if (!$getVarTypeFromParamTag) {
                 $parameter->setVarType(NodeConverter::getValueFromNode($param->type));
             }
         } elseif ($getVarTypeFromParamTag) {
             // if there is not type hint but a varType in the param tag,
             // we set the varType of the parameter
             $paramTag = explode(' ', $paramTags[$position]);
             if ($paramTag[0] !== '$' . $param->name) {
                 $parameter->setVarType($paramTag[0]);
                 $parameter->setTypeForParamTag($paramTag[0]);
             }
         }
         if (!is_null($param->default)) {
             $parameter->setDefaultValue($param->default);
         }
         $object->setParameter($parameter);
         $position++;
     }
     $object->updateParamTags();
     return $object;
 }