private function parseOperatorNode(Node\Expr $node) { $nodeType = str_replace('Expr_', '', $node->getType()); switch (true) { case isset(self::$assignOperatorsMap[$nodeType]): return Expression::assign($this->parseNode($node->var), self::$assignOperatorsMap[$nodeType], $this->parseNode($node->expr)); case $node instanceof Node\Expr\Instanceof_: return Expression::binaryOperation($this->parseNode($node->expr), Operators\Binary::IS_INSTANCE_OF, $this->parseNameNode($node->class)); case isset(self::$binaryOperatorsMap[$nodeType]): return Expression::binaryOperation($this->parseNode($node->left), self::$binaryOperatorsMap[$nodeType], $this->parseNode($node->right)); case isset(self::$unaryOperatorsMap[$nodeType]): return Expression::unaryOperation(self::$unaryOperatorsMap[$nodeType], $this->parseNode(isset($node->expr) ? $node->expr : $node->var)); case isset(self::$castOperatorMap[$nodeType]): return Expression::cast(self::$castOperatorMap[$nodeType], $this->parseNode($node->expr)); default: return null; } }
/** * Determines whether or not a parameter can be reference (e.g. vars can be referenced, while function calls cannot) * * @param \PhpParser\Node\Expr $value * @return bool */ private static function canRef($value) { $type = $value->getType(); if (isset(self::$can_ref[$type])) { return true; } else { if ($value instanceof \PhpParser\Node\Expr\ArrayDimFetch) { if (!self::canRef($value->var)) { return false; } // an ugly hack for ArrayAccess objects that are used as "$this['something']" if ($value->var instanceof \PhpParser\Node\Expr\Variable && $value->var->name == 'this') { return false; } return true; } } return false; }