예제 #1
0
 /**
  * @param Assign $node
  * @param Expr   $leftNode
  * @param Expr   $rightNode
  * @param string $operatorString
  */
 private function arrayDimFetchCase($node, $leftNode, $rightNode, $operatorString, $precedence, $associativity)
 {
     $this->logger->trace(self::getType() . ' ' . __LINE__, $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
     $head = '';
     if ($leftNode instanceof ArrayDimFetch) {
         if (false === ($splitedArray = $this->arrayManipulator->arrayNeedToBeSplit($leftNode))) {
             $leftString = $this->dispatcher->pPrec($leftNode, $precedence, $associativity, 1);
         } else {
             $result = $this->dispatcher->pExpr_ArrayDimFetch($leftNode, true);
             $head .= $result['head'];
             $leftString = $result['lastExpr'];
         }
     } else {
         $leftString = $this->dispatcher->pPrec($leftNode, $precedence, $associativity, -1);
     }
     if ($rightNode instanceof ArrayDimFetch) {
         if (false === ($splitedArray = $this->arrayManipulator->arrayNeedToBeSplit($rightNode))) {
             $rightString = $this->dispatcher->pPrec($rightNode, $precedence, $associativity, 1);
         } else {
             $result = $this->dispatcher->pExpr_ArrayDimFetch($rightNode, true);
             $head .= $result['head'];
             $rightString = $result['lastExpr'];
         }
     } elseif ($this->isSomething($rightNode)) {
         $this->logger->trace(self::getType() . ' ' . __LINE__, $node, $this->dispatcher->getMetadata()->getFullQualifiedNameClass());
         // @TODO add test case for each
         $rightString = $this->dispatcher->pPrec($rightNode, $precedence, $associativity, 1);
     } else {
         $head .= $this->dispatcher->pPrec($rightNode, $precedence, $associativity, 1) . ";\n";
         $rightString = $this->dispatcher->p($rightNode->var);
     }
     return $head . 'let ' . $leftString . $operatorString . $rightString;
 }
예제 #2
0
 /**
  * @param \ArrayIterator|array $node
  * @param array                $vars
  *
  * @return \ArrayIterator|array
  */
 private function collectVars($node, array $vars = array())
 {
     $noFetcher = new NodeFetcher();
     foreach ($noFetcher->foreachNodes($node) as &$stmt) {
         if ($stmt['node'] instanceof Expr\Assign) {
             if ($stmt['node']->var instanceof Expr\PropertyFetch === false && $stmt['node']->var instanceof Expr\StaticPropertyFetch === false && $stmt['node']->var instanceof Expr\ArrayDimFetch === false && $stmt['node']->var instanceof Expr\List_ === false) {
                 if (is_object($stmt['node']->var->name) === false) {
                     // if true it is a dynamic var
                     $vars[] = $stmt['node']->var->name;
                 }
             } elseif ($stmt['node']->var instanceof Expr\List_ === true) {
                 $varInList = array();
                 foreach ($stmt['node']->var->vars as $var) {
                     if (null !== $var) {
                         $varInList[] = $this->dispatcher->p($var);
                         if ($var instanceof Expr\ArrayDimFetch === false) {
                             $vars[] = $this->dispatcher->p($var);
                         }
                     }
                 }
                 $vars[] = 'tmpList' . str_replace(array('[', ']', '"'), '', implode('', $varInList));
             }
         } elseif ($stmt['node'] instanceof Stmt\Foreach_) {
             if (null !== $stmt['node']->keyVar) {
                 $vars[] = $stmt['node']->keyVar->name;
             }
             $vars[] = $stmt['node']->valueVar->name;
         } elseif ($stmt['node'] instanceof Stmt\For_) {
             foreach ($stmt['node']->init as $init) {
                 if ($init instanceof Expr\Assign) {
                     $vars[] = $init->var->name;
                 }
             }
         } elseif ($stmt['node'] instanceof Stmt\If_) {
             foreach ($this->nodeFetcher->foreachNodes($stmt['node']->cond) as $nodeData) {
                 $node = $nodeData['node'];
                 if ($node instanceof Expr\Array_) {
                     $vars[] = 'tmpArray' . md5(serialize($node->items));
                 }
             }
         } elseif ($stmt['node'] instanceof Stmt\Catch_) {
             $vars[] = $stmt['node']->var;
         } elseif ($stmt['node'] instanceof Stmt\Return_ && $stmt['node']->expr instanceof Expr\Array_) {
             $vars[] = 'tmpArray' . md5(serialize($stmt['node']->expr->items));
         } elseif ($stmt['node'] instanceof Stmt\Static_) {
             foreach ($stmt['node']->vars as $var) {
                 $vars[] = $var->name;
             }
         } elseif ($stmt['node'] instanceof Arg && $stmt['node']->value instanceof Expr\Array_) {
             $vars[] = 'tmpArray' . md5(serialize($stmt['node']->value->items));
         }
         if ($stmt['node'] instanceof Expr\ArrayDimFetch && !in_array("PhpParser\\Node\\Expr\\ArrayDimFetch", $stmt['parentClass'])) {
             $varCreatedInArray = $this->dispatcher->pExpr_ArrayDimFetch($stmt['node'], true);
             foreach ($varCreatedInArray['vars'] as $var) {
                 $vars[] = $var;
             }
         }
     }
     $vars = array_map(array($this->reservedWordReplacer, 'replace'), $vars);
     return $vars;
 }