src/Tokenizer/TokenRegistry.php
public function replace(Token $oldToken, array $newTokens)
    {
        // Get the current key of the element.
        $key = array_search($oldToken, $this->registry, true);
        if (false === $key) {
            return $this;
        }
        $replacement = array();

        // Check for any non-token-elements and remove them.
        foreach ($newTokens as $token) {
            if (! $token instanceof Token) {
                continue;
            }
            $replacement[] = $token;
        }

        // Replace the old element with the newly created array
        array_splice($this->registry, $key, 1, $replacement);

        return $this;
    }
public function replace(Token $oldToken, array $newTokens)
    {
        // Get the current key of the element.
        $key = array_search($oldToken, $this->registry, true);
        if (false === $key) {
            return $this;
        }
        $replacement = array();

        // Check for any non-token-elements and remove them.
        foreach ($newTokens as $token) {
            if (! $token instanceof Token) {
                continue;
            }
            $replacement[] = $token;
        }

        // Replace the old element with the newly created array
        array_splice($this->registry, $key, 1, $replacement);

        return $this;
    }
Replace a given token with an array of new tokens

This will be used when a tokenizer has to replace a token that has been
divided into multiple tokens.

@param Token   $oldToken  The token to be replaced
@param Token[] $newTokens The array of tokens replacing the old one

@return TokenRegistry