private function fixArray(Tokens $tokens, &$index)
 {
     $tokens[$index]->clear();
     $bracesLevel = 0;
     ++$index;
     for ($c = $tokens->count(); $index < $c; ++$index) {
         $token = $tokens[$index];
         if ('(' === $token->content) {
             if (0 === $bracesLevel) {
                 $tokens[$index]->content = '[';
             }
             ++$bracesLevel;
             continue;
         }
         if ($token->isGivenKind(T_ARRAY) && '(' === $tokens->getNextNonWhitespace($index)->content) {
             $this->fixArray($tokens, $index);
             continue;
         }
         if (')' === $token->content) {
             --$bracesLevel;
             if (0 === $bracesLevel) {
                 $tokens[$index]->content = ']';
                 break;
             }
         }
     }
 }
 private function fixArray(Tokens $tokens, &$index)
 {
     $bracesLevel = 0;
     // Skip only when its an array, for short arrays we need the brace for correct
     // level counting
     if ($tokens[$index]->isGivenKind(T_ARRAY)) {
         ++$index;
     }
     $multiline = $tokens->isArrayMultiLine($index);
     for ($c = $tokens->count(); $index < $c; ++$index) {
         $token = $tokens[$index];
         if ('(' === $token->content || '[' === $token->content) {
             ++$bracesLevel;
             continue;
         }
         if ($token->isGivenKind(T_ARRAY) || $tokens->isShortArray($index)) {
             $this->fixArray($tokens, $index);
             continue;
         }
         if (')' === $token->content || ']' === $token->content) {
             --$bracesLevel;
             $foundIndex = null;
             if (!$multiline && 0 === $bracesLevel && ',' === $tokens->getPrevNonWhitespace($index, array(), $foundIndex)->content) {
                 $tokens->removeTrailingWhitespace($foundIndex);
                 $tokens[$foundIndex]->clear();
             }
             if (0 === $bracesLevel) {
                 break;
             }
         }
     }
 }
Beispiel #3
0
 private function fixSpaceAroundToken(Tokens $tokens)
 {
     $controlTokens = $this->getControlTokens();
     for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
         $token = $tokens[$index];
         if ($token->isGivenKind($controlTokens) || $token->isGivenKind(T_USE)) {
             $tokens->ensureWhitespaceAtIndex($index + 1, 0, ' ');
             $prevToken = $tokens[$index - 1];
             if (!$prevToken->isWhitespace() && !$prevToken->isComment() && !$prevToken->isGivenKind(T_OPEN_TAG)) {
                 $tokens->ensureWhitespaceAtIndex($index - 1, 1, ' ');
             }
         }
     }
 }