/** * Creates a new array lookup. * * @param \Pharborist\ExpressionNode $array * The expression representing the array (usually a VariableNode). * @param \Pharborist\ExpressionNode $key * The expression representing the key (usually a string). * * @return static */ public static function create(ExpressionNode $array, ExpressionNode $key) { $node = new static(); /** @var Node $array */ $node->addChild($array, 'array'); $node->addChild(Token::openBracket()); /** @var Node $key */ $node->addChild($key, 'key'); $node->addChild(Token::closeBracket()); return $node; }
public function visitArrayNode(ArrayNode $node) { $nested = FALSE; if ($node->parents(Filter::isInstanceOf('\\Pharborist\\Types\\ArrayNode'))->isNotEmpty()) { $this->indentLevel++; $nested = TRUE; } if ($this->config['force_array_new_style']) { $first = $node->firstChild(); /** @var TokenNode $first */ if ($first->getType() === T_ARRAY) { $open_paren = $first->nextUntil(Filter::isTokenType('('), TRUE)->last()->get(0); $open_paren->previousAll()->remove(); $open_paren->replaceWith(Token::openBracket()); $close_paren = $node->lastChild(); $close_paren->replaceWith(Token::closeBracket()); } } // Remove space after T_ARRAY. $first = $node->firstChild(); /** @var TokenNode $first */ if ($first->getType() === T_ARRAY) { $this->removeSpaceAfter($first); } // Remove whitespace before first element. $this->removeSpaceBefore($node->getElementList()); // Remove whitespace after last element. $this->removeSpaceAfter($node->getElementList()); // Remove trailing comma. $last = $node->getElementList()->lastChild(); if ($last instanceof TokenNode && $last->getType() === ',') { $last->remove(); } $this->nodeData[$node] = $nested; }