/** * @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; }
/** * @param Stmt\If_ $node * * @return string */ public function convert(Stmt\If_ $node) { $collected = $this->assignManipulator->collectAssignInCondition($node->cond); $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond); if (empty($node->stmts)) { $node->stmts = array(new Stmt\Echo_(array(new Scalar\String_('not allowed')))); $this->logger->logIncompatibility('Empty if', 'Empty if not allowed, add "echo not allowed"', $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass()); } return $collected->getCollected() . 'if ' . $this->dispatcher->p($node->cond) . ' {' . $this->dispatcher->pStmts($node->stmts) . "\n" . '}' . $this->implodeElseIfs($node); }
/** * @param Expr\ArrayDimFetch $node */ private function findComplexArrayDimFetch($node, $collected = array()) { if ($this->isInvalidInArrayDimFetch($node) === true) { if ($node->dim instanceof Expr\FuncCall) { $this->logger->logIncompatibility('ArrayFetchDim', 'supported funccall in array', $node, $this->dispatcher->getMetadata()->getClass()); } else { $collected[] = array('expr' => $this->dispatcher->p($node->dim) . ";\n", 'splitTab' => true, 'var' => $this->dispatcher->p($node->dim->var)); } } else { if ($node->dim === null) { $collected[] = array('expr' => $this->dispatcher->p($node->var), 'splitTab' => false); } else { $collected[] = array('expr' => $this->dispatcher->p($node->dim), 'splitTab' => false); } } if ($node->var instanceof Expr\ArrayDimFetch) { $collected = $this->findComplexArrayDimFetch($node->var, $collected); } else { $collected[] = $node->var; } return $collected; }