コード例 #1
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'];
     }
 }