/**
  * @param Stmt\ClassMethod $node
  *
  * @return string
  */
 public function convert(Stmt\ClassMethod $node)
 {
     $types = $this->typeFinder->getTypes($node, $this->dispatcher->getMetadata());
     foreach ($node->params as $param) {
         if ($param->byRef === true) {
             $this->logger->logIncompatibility('reference', sprintf('Reference not supported in parametter (var "%s")', $param->name), $param, $this->dispatcher->getMetadata()->getClass());
         }
     }
     if ($node->byRef) {
         $this->logger->logIncompatibility('reference', 'Reference not supported', $node, $this->dispatcher->getMetadata()->getClass());
     }
     $this->dispatcher->setLastMethod($node->name);
     $stmt = $this->dispatcher->pModifiers($node->type) . 'function ' . $node->name . '(';
     $varsInMethodSign = array();
     if (isset($types['params']) === true) {
         $params = array();
         foreach ($types['params'] as $type) {
             $varsInMethodSign[] = $type['name'];
             $stringType = $this->printType($type);
             $params[] = (!empty($stringType) ? $stringType . ' ' : '') . '' . $type['name'] . ($type['default'] === null ? '' : ' = ' . $this->dispatcher->p($type['default']));
         }
         $stmt .= implode(', ', $params);
     }
     $stmt .= ')';
     $stmt .= $this->printReturn($node, $types);
     $stmt .= (null !== $node->stmts ? "\n{" . $this->printVars($node, $varsInMethodSign) . $this->dispatcher->pStmts($node->stmts) . "\n}" : ';') . "\n";
     return $stmt;
 }
Exemplo n.º 2
0
 /**
  * @param Stmt\ClassMethod $node
  *
  * @return string
  */
 public function convert(Stmt\ClassMethod $node)
 {
     $types = $this->typeFinder->getTypes($node, $this->dispatcher->getMetadata());
     $this->dispatcher->setLastMethod($node->name);
     $stmt = $this->dispatcher->pModifiers($node->type) . 'function ' . ($node->byRef ? '&' : '') . $node->name . '(';
     $varsInMethodSign = array();
     if (isset($types['params']) === true) {
         $params = array();
         foreach ($types['params'] as $type) {
             $varsInMethodSign[] = $type['name'];
             $stringType = $this->printType($type);
             $params[] = (!empty($stringType) ? $stringType . ' ' : '') . '' . $type['name'] . ($type['default'] === null ? '' : ' = ' . $this->dispatcher->p($type['default']));
         }
         $stmt .= implode(', ', $params);
     }
     $stmt .= ')';
     $stmt .= $this->printReturn($node, $types);
     $stmt .= (null !== $node->stmts ? "\n{" . $this->printVars($node, $varsInMethodSign) . $this->dispatcher->pStmts($node->stmts) . "\n}" : ';') . "\n";
     return $stmt;
 }