Exemplo n.º 1
0
 /**
  * @param Expr\Assign $node
  *
  * @return string
  */
 public function convert(Expr\Assign $node, $extract = true)
 {
     $type = 'Expr_Assign';
     $leftNode = $node->var;
     $operatorString = ' = ';
     $rightNode = $node->expr;
     list($precedence, $associativity) = $this->dispatcher->getPrecedenceMap($type);
     if ($rightNode instanceof Expr\Array_) {
         $this->logger->trace(self::getType() . ' ' . __LINE__, $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
         $collect = $this->dispatcher->pExpr_Array($rightNode, true);
         return ($extract === true ? $collect->getCollected() : '') . 'let ' . $this->dispatcher->pPrec($leftNode, $precedence, $associativity, -1) . $operatorString . ' ' . $collect->getExpr();
     } elseif (($rightNode instanceof Expr\MethodCall || $rightNode instanceof Expr\FuncCall) && $leftNode instanceof Expr\List_ === false) {
         $collected = $this->convertCall($node, new ArrayDto());
         return $collected['extracted']->getCollected() . 'let ' . $this->dispatcher->pPrec($leftNode, $precedence, $associativity, -1) . $operatorString . ' ' . $this->dispatcher->p($collected['node']->expr);
     } elseif ($rightNode instanceof Expr\BinaryOp\Concat) {
         $collected = $this->convertConcat($node->expr, new ArrayDto());
         return $collected['extracted']->getCollected() . 'let ' . $this->dispatcher->pPrec($leftNode, $precedence, $associativity, -1) . $operatorString . ' ' . $this->dispatcher->p($collected['node']);
     } elseif ($rightNode instanceof Expr\Ternary) {
         $collect = $this->dispatcher->pExpr_Ternary($rightNode, true);
         return $collect->getCollected() . 'let ' . $this->dispatcher->pPrec($leftNode, $precedence, $associativity, -1) . $operatorString . ' ' . $collect->getExpr();
     } elseif ($leftNode instanceof Expr\List_) {
         return $this->convertListStmtToAssign($node);
     } elseif ($leftNode instanceof Expr\ArrayDimFetch || $rightNode instanceof Expr\ArrayDimFetch) {
         return $this->arrayDimFetchCase($node, $leftNode, $rightNode, $operatorString, $precedence, $associativity, $extract);
     } elseif ($rightNode instanceof Expr\Assign) {
         // multiple assign
         $valueToAssign = ' = ' . $this->dispatcher->p($this->findValueToAssign($rightNode));
         $vars = array($this->dispatcher->pPrec($leftNode, $precedence, $associativity, -1));
         foreach ($this->findVarToAssign($rightNode) as $nodeAssigned) {
             $vars[] = $nodeAssigned;
         }
         $toReturn = '';
         foreach ($vars as $var) {
             $toReturn .= 'let ' . $var . $valueToAssign . ";\n";
         }
         return $toReturn;
     } elseif ($rightNode instanceof Variable || $rightNode instanceof Scalar || $rightNode instanceof Array_) {
         $this->logger->trace(self::getType() . ' ' . __LINE__, $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
         return 'let ' . $this->dispatcher->pPrec($leftNode, $precedence, $associativity, -1) . $operatorString . $this->dispatcher->pPrec($rightNode, $precedence, $associativity, 1);
     } else {
         $this->logger->trace(self::getType() . ' ' . __LINE__, $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
         return 'let ' . $this->dispatcher->pPrec($leftNode, $precedence, $associativity, -1) . $operatorString . ' ' . $this->dispatcher->p($rightNode);
     }
 }