PhpCsFixer\Tokenizer\Tokens::clearEmptyTokens PHP Method

clearEmptyTokens() public method

Empty tokens can occur e.g. after calling clear on item of collection.
public clearEmptyTokens ( )
    public function clearEmptyTokens()
    {
        $limit = $this->count();
        $index = 0;
        for (; $index < $limit; ++$index) {
            if ($this[$index]->isEmpty()) {
                break;
            }
        }
        // no empty token found, therefore there is no need to override collection
        if ($limit === $index) {
            return;
        }
        for ($count = $index; $index < $limit; ++$index) {
            $token = $this[$index];
            if (!$token->isEmpty()) {
                $this[$count++] = $token;
            }
        }
        $this->setSize($count);
    }

Usage Example

 private function runHelperFixers(\SplFileInfo $file, Tokens $tokens)
 {
     /** @var AbstractAlignFixerHelper $helper */
     foreach ($this->alignFixerHelpers as $helper) {
         if ($tokens->isChanged()) {
             $tokens->clearEmptyTokens();
         }
         $helper->fix($file, $tokens);
     }
 }