Beispiel #1
0
 private function clearIncludies(Tokens $tokens, array $includies)
 {
     foreach (array_reverse($includies) as $includy) {
         if ($includy['end']) {
             $tokens->removeLeadingWhitespace($includy['end']);
         }
         $braces = $includy['braces'];
         if ($braces) {
             $nextToken = $tokens->getNextNonWhitespace($includy['braces']['close']);
             if (!$nextToken->isArray() && ';' === $nextToken->content) {
                 $tokens->removeLeadingWhitespace($braces['open']);
                 $tokens->removeTrailingWhitespace($braces['open']);
                 $tokens->removeLeadingWhitespace($braces['close']);
                 $tokens->removeTrailingWhitespace($braces['close']);
                 $tokens[$braces['open']] = new Token(array(T_WHITESPACE, ' '));
                 $tokens[$braces['close']]->clear();
             }
         }
         $nextIndex = $includy['begin'] + 1;
         $nextToken = $tokens[$nextIndex];
         while ($nextToken->isEmpty()) {
             $nextToken = $tokens[++$nextIndex];
         }
         if ($nextToken->isWhitespace()) {
             $nextToken->content = ' ';
         } elseif ($braces) {
             $tokens->insertAt($includy['begin'] + 1, new Token(array(T_WHITESPACE, ' ')));
         }
     }
 }
 private function ensureWhitespaceExistance(Tokens $tokens, $index, $after)
 {
     $indexChange = $after ? 0 : 1;
     $token = $tokens[$index];
     if ($token->isWhitespace()) {
         return;
     }
     $tokens->insertAt($index + $indexChange, new Token(array(T_WHITESPACE, ' ', $token->line)));
 }
 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(','));
     }
 }