PhpCsFixer\Tokenizer\Tokens::removeTrailingWhitespace PHP Method

removeTrailingWhitespace() public method

Removes all the trailing whitespace.
public removeTrailingWhitespace ( integer $index, null | string $whitespaces = null )
$index integer
$whitespaces null | string optional whitespaces characters for Token::isWhitespace
    public function removeTrailingWhitespace($index, $whitespaces = null)
    {
        if (isset($this[$index + 1]) && $this[$index + 1]->isWhitespace($whitespaces)) {
            $this[$index + 1]->clear();
        }
    }

Usage Example

Exemplo n.º 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[$tokens->getNextMeaningfulToken($braces['close'])];
             if ($nextToken->equals(';')) {
                 $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->setContent(' ');
         } elseif ($braces || $tokens[$nextIndex]->isGivenKind(array(T_VARIABLE, T_CONSTANT_ENCAPSED_STRING, T_COMMENT))) {
             $tokens->insertAt($includy['begin'] + 1, new Token(array(T_WHITESPACE, ' ')));
         }
     }
 }
All Usage Examples Of PhpCsFixer\Tokenizer\Tokens::removeTrailingWhitespace