public function convert(Stmt\Do_ $node) { $condition = clone $node; $collected = $this->assignManipulator->collectAssignInCondition($condition->cond); $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond); return 'do {' . $this->dispatcher->pStmts($node->stmts) . $collected->getCollected() . "\n" . '} while (' . $this->dispatcher->p($node->cond) . ');'; }
public function convert(Stmt\Do_ $node) { $condition = clone $node; $collected = $this->assignManipulator->collectAssignInCondition($condition->cond); $collected = !empty($collected['extracted']) ? "\n" . implode("\n", $collected['extracted']) : ''; $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond); return 'do {' . $this->dispatcher->pStmts($node->stmts) . $collected . "\n" . '} while (' . $this->dispatcher->p($node->cond) . ');'; }
/** * @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->logNode('Empty if not allowed, add "echo not allowed"', $node, $this->dispatcher->getMetadata()->getClass()); } return implode(";\n", $collected['extracted']) . "\n" . 'if ' . $this->dispatcher->p($node->cond) . ' {' . $this->dispatcher->pStmts($node->stmts) . "\n" . '}' . $this->implodeElseIfs($node); }
/** * @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\FuncCall $node * * @return string */ public function convert(Expr\FuncCall $node) { $collected = $this->assignManipulator->collectAssignInCondition($node->args); $node->args = $this->assignManipulator->transformAssignInConditionTest($node->args); if ($node->name instanceof Expr\Variable) { $instanciation = '{' . $this->dispatcher->p($node->name) . '}'; } else { $instanciation = $this->dispatcher->p($node->name); } return (!empty($collected['extracted']) ? implode(";\n", $collected['extracted']) . "\n" : '') . $instanciation . '(' . $this->dispatcher->pCommaSeparated($node->args) . ')'; }
/** * @param Expr\Array_ $node * @param bool $returnAsArray * * @return string|array */ public function convert(Expr\Array_ $node, $returnAsArray = false) { $collected = $this->assignManipulator->collectAssignInCondition($node->items); $node->items = $this->assignManipulator->transformAssignInConditionTest($node->items); $collected['expr'] = '[' . $this->dispatcher->pCommaSeparated($node->items) . ']'; if ($returnAsArray === true) { return $collected; } else { return (!empty($collected['extracted']) ? implode(";\n", $collected['extracted']) . "\n" : '') . $collected['expr']; } }
/** * @param Expr\FuncCall $node * * @return string */ public function convert(Expr\FuncCall $node) { $collected = $this->assignManipulator->collectAssignInCondition($node->args); $node->args = $this->assignManipulator->transformAssignInConditionTest($node->args); if ($node->name instanceof Expr\Variable) { $instanciation = '{' . $this->dispatcher->p($node->name) . '}'; } else { $instanciation = $this->dispatcher->p($node->name); } return $collected->getCollected() . $instanciation . '(' . $this->dispatcher->pCommaSeparated($node->args) . ')'; }
/** * @param Expr\Array_ $node * @param bool $returnAsArray * * @return string|array */ public function convert(Expr\Array_ $node, $returnAsArray = false) { $collected = $this->assignManipulator->collectAssignInCondition($node->items); $node->items = $this->assignManipulator->transformAssignInConditionTest($node->items); $collected->setExpr('[' . $this->dispatcher->pCommaSeparated($node->items) . ']'); if ($returnAsArray === true) { return $collected; } else { return $collected->getCollected() . $collected->getExpr(); } }
/** * @param Expr\Ternary $node * @param string $returnAsArray * * @return string */ public function convert(Expr\Ternary $node, $returnAsArray = false) { // a bit of cheating: we treat the ternary as a binary op where the ?...: part is the operator. // this is okay because the part between ? and : never needs parentheses. $collected = $this->assignManipulator->collectAssignInCondition($node->cond); $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond); $collected['expr'] = $this->dispatcher->pInfixOp('Expr_Ternary', $node->cond, ' ?' . (null !== $node->if ? ' ' . $this->dispatcher->p($node->if) . ' ' : '') . ': ', $node->else); if ($returnAsArray === true) { return $collected; } else { return implode(";\n", $collected['extracted']) . "\n" . $collected['expr']; } }
private function convertCall($node, ArrayDto $collected) { if (property_exists($node, 'left') === true && ($node->left instanceof Expr\MethodCall || $node->left instanceof Expr\FuncCall)) { $collected = $this->assignManipulator->collectAssignInCondition($node->left->args, $collected); $node->left->args = $this->assignManipulator->transformAssignInConditionTest($node->left->args); } if (property_exists($node, 'right') === true && ($node->right instanceof Expr\MethodCall || $node->right instanceof Expr\FuncCall)) { $collected = $this->assignManipulator->collectAssignInCondition($node->right->args, $collected); $node->right->args = $this->assignManipulator->transformAssignInConditionTest($node->right->args); } if (property_exists($node, 'expr') === true && ($node->expr instanceof Expr\MethodCall || $node->expr instanceof Expr\FuncCall)) { $collected = $this->assignManipulator->collectAssignInCondition($node->expr->args, $collected); $node->expr->args = $this->assignManipulator->transformAssignInConditionTest($node->expr->args); } return array('extracted' => $collected, 'node' => $node); }
/** * @param Expr\MethodCall $node * * @return string */ public function convert(Expr\MethodCall $node) { $collected = $this->assignManipulator->collectAssignInCondition($node->args); $node->args = $this->assignManipulator->transformAssignInConditionTest($node->args); return $collected->getCollected() . $this->dispatcher->pVarOrNewExpr($node->var) . '->' . $this->dispatcher->pObjectProperty($node->name) . '(' . $this->dispatcher->pCommaSeparated($node->args) . ')'; }
/** * @param Stmt\Return_ $node * * @return string */ public function convert(Stmt\Return_ $node) { $collected = $this->assignManipulator->collectAssignInCondition($node->expr); $node->expr = $this->assignManipulator->transformAssignInConditionTest($node->expr); return $collected->getCollected() . 'return' . (null !== $node->expr ? ' ' . $this->dispatcher->p($node->expr) : '') . ';'; }
/** * @param Stmt\Return_ $node * * @return string */ public function convert(Stmt\Return_ $node) { $collected = $this->assignManipulator->collectAssignInCondition($node->expr); $node->expr = $this->assignManipulator->transformAssignInConditionTest($node->expr); return implode(";\n", $collected['extracted']) . "\n" . 'return' . (null !== $node->expr ? ' ' . $this->dispatcher->p($node->expr) : '') . ';'; }
/** * @param Stmt\While_ $node * * @return string */ public function convert(Stmt\While_ $node) { $collected = $this->assignManipulator->collectAssignInCondition($node->cond); $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond); return implode(";\n", $collected['extracted']) . "\n" . 'while (' . $this->dispatcher->p($node->cond) . ') {' . $this->dispatcher->pStmts($node->stmts) . "\n" . implode(";\n", $collected['extracted']) . "\n" . '}'; }
/** * @param Expr\MethodCall $node * * @return string */ public function convert(Expr\MethodCall $node) { $collected = $this->assignManipulator->collectAssignInCondition($node->args); $node->args = $this->assignManipulator->transformAssignInConditionTest($node->args); return (!empty($collected['extracted']) ? implode("\n", $collected['extracted']) . "\n" : '') . $this->dispatcher->pVarOrNewExpr($node->var) . '->' . $this->dispatcher->pObjectProperty($node->name) . '(' . $this->dispatcher->pCommaSeparated($node->args) . ')'; }
/** * @param Stmt\While_ $node * * @return string */ public function convert(Stmt\While_ $node) { $collected = $this->assignManipulator->collectAssignInCondition($node->cond); $node->cond = $this->assignManipulator->transformAssignInConditionTest($node->cond); return $collected->getCollected() . 'while (' . $this->dispatcher->p($node->cond) . ') {' . $this->dispatcher->pStmts($node->stmts) . "\n" . $collected->getCollected() . '}'; }