private function fixArray(Tokens $tokens, $index)
 {
     $bracesLevel = 0;
     $startIndex = $index;
     if ($tokens[$index]->isGivenKind(T_ARRAY)) {
         $tokens->getNextTokenOfKind($index, array('(', '['), $startIndex);
     }
     if (!$tokens->isArrayMultiLine($index)) {
         return;
     }
     if ($tokens[$startIndex]->equals('(')) {
         $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
     } else {
         $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_SQUARE_BRACE, $startIndex);
     }
     $beforeEndIndex = null;
     $beforeEndToken = $tokens->getTokenNotOfKindSibling($endIndex, -1, array(array(T_WHITESPACE), array(T_COMMENT), array(T_DOC_COMMENT)), $beforeEndIndex);
     // if there is some item between braces then add `,` after it
     if ($startIndex !== $beforeEndIndex && !$beforeEndToken->equals(',')) {
         $tokens->insertAt($beforeEndIndex + 1, new Token(','));
     }
 }
Ejemplo n.º 2
0
 private function findStatementEnd(Tokens $tokens, $parenthesisEndIndex)
 {
     $nextIndex = null;
     $nextToken = $tokens->getNextNonWhitespace($parenthesisEndIndex, array(), $nextIndex);
     if (!$nextToken) {
         return $parenthesisEndIndex;
     }
     if ($nextToken->equals('{')) {
         return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $nextIndex);
     }
     if ($nextToken->isGivenKind($this->getControlTokens())) {
         $parenthesisEndIndex = $this->findParenthesisEnd($tokens, $nextIndex);
         $endIndex = $this->findStatementEnd($tokens, $parenthesisEndIndex);
         if ($nextToken->isGivenKind(T_IF)) {
             $nextIndex = null;
             $nextToken = $tokens->getNextNonWhitespace($endIndex, array(), $nextIndex);
             if ($nextToken && $nextToken->isGivenKind($this->getControlContinuationTokens())) {
                 $parenthesisEndIndex = $this->findParenthesisEnd($tokens, $nextIndex);
                 return $this->findStatementEnd($tokens, $parenthesisEndIndex);
             }
         }
         return $endIndex;
     }
     $index = $parenthesisEndIndex;
     while (true) {
         $token = $tokens[++$index];
         if (';' === $token->content) {
             break;
         }
     }
     return $index;
 }