コード例 #1
0
 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;
             }
         }
     }
 }