/** * Check if the array at index is multiline. * * This only checks the root-level of the array. * * @param int $index * * @return bool */ public function isArrayMultiLine($index) { if (!$this->isArray($index)) { throw new \InvalidArgumentException('Not an array at given index'); } $tokens = $this->tokens; // Skip only when its an array, for short arrays we need the brace for correct // level counting if ($tokens[$index]->isGivenKind(T_ARRAY)) { $index = $tokens->getNextMeaningfulToken($index); } $endIndex = $tokens[$index]->equals('(') ? $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index) : $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index); for (++$index; $index < $endIndex; ++$index) { $token = $tokens[$index]; $blockType = Tokens::detectBlockType($token); if ($blockType && $blockType['isStart']) { $index = $tokens->findBlockEnd($blockType['type'], $index); continue; } if ($token->isWhitespace() && !$tokens[$index - 1]->isGivenKind(T_END_HEREDOC) && false !== strpos($token->getContent(), "\n")) { return true; } } return false; }