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;
             }
         }
     }
 }
示例#2
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, ' ')));
         }
     }
 }
示例#3
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;
 }