Esempio n. 1
0
 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) . ');';
 }
Esempio n. 2
0
 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) . ');';
 }
Esempio n. 3
0
 /**
  * @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) . ')';
 }
Esempio n. 4
0
 /**
  * @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();
     }
 }
Esempio n. 7
0
 /**
  * @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'];
     }
 }
Esempio n. 8
0
 /**
  * @param Stmt\If_ $node
  *
  * @return string
  */
 private function implodeElseIfs(Stmt\If_ $node)
 {
     $elseCount = 0;
     $toReturn = '';
     foreach ($node->elseifs as $elseIf) {
         $collected = $this->assignManipulator->collectAssignInCondition($elseIf->cond);
         if (!empty($collected['extracted'])) {
             $elseCount++;
             $toReturn .= ' else { ' . "\n" . $this->dispatcher->p(new Stmt\If_($elseIf->cond, array('stmts' => $elseIf->stmts))) . "\n";
         } else {
             $toReturn .= $this->dispatcher->pStmt_ElseIf($elseIf);
         }
     }
     $toReturn .= null !== $node->else ? $this->dispatcher->p($node->else) : '';
     return $toReturn . str_repeat('}', $elseCount);
 }
 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) : '') . ';';
 }
Esempio n. 12
0
 /**
  * @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) : '') . ';';
 }
Esempio n. 13
0
 /**
  * @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" . '}';
 }
Esempio n. 14
0
 /**
  * @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) . ')';
 }
Esempio n. 15
0
 /**
  * @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() . '}';
 }