public function expect(string $type, $value = null, string $message = null): void
    {
        if ($this->test($type, $value)) {
            return;
        }

        $currentToken = $this->getCurrent();

        if ($message === null) {
            // Let's create a default message
            $formattedMessage = \sprintf(
                'Expected token type %s%s',
                $type,
                $value === null ? '' : " with value \"$value\""
            );

            if ($currentToken === null) {
                $formattedMessage .= ', got end of stream';
            } else {
                $formattedMessage .= \sprintf(
                    ', got %s with value \"%s\"',
                    $currentToken->type,
                    $currentToken->value
                );
            }
        } else {
            $formattedMessage = \sprintf(
                $message,
                $currentToken === null ? 'T_EOF' : $currentToken->type,
                $currentToken === null ? 'end of stream' : $currentToken->value
            );
        }

        throw new InvalidArgumentException($formattedMessage);
    }
public function expect(string $type, $value = null, string $message = null): void
    {
        if ($this->test($type, $value)) {
            return;
        }

        $currentToken = $this->getCurrent();

        if ($message === null) {
            // Let's create a default message
            $formattedMessage = \sprintf(
                'Expected token type %s%s',
                $type,
                $value === null ? '' : " with value \"$value\""
            );

            if ($currentToken === null) {
                $formattedMessage .= ', got end of stream';
            } else {
                $formattedMessage .= \sprintf(
                    ', got %s with value \"%s\"',
                    $currentToken->type,
                    $currentToken->value
                );
            }
        } else {
            $formattedMessage = \sprintf(
                $message,
                $currentToken === null ? 'T_EOF' : $currentToken->type,
                $currentToken === null ? 'end of stream' : $currentToken->value
            );
        }

        throw new InvalidArgumentException($formattedMessage);
    }
public function expect ( string $ type , $ value = null , string $ message = null ) : void { if ( $ this -> test ( $ type , $ value ) ) { return ; } $ currentToken = $ this -> getCurrent ( ) ; if ( $ message === null ) { // Let's create a default message $ formattedMessage = \ sprintf ( 'Expected token type %s%s' , $ type , $ value === null ? '' : " with value \"$value\"" ) ; if ( $ currentToken === null ) { $ formattedMessage .= ', got end of stream' ; } else { $ formattedMessage .= \ sprintf ( ', got %s with value \"%s\"' , $ currentToken -> type , $ currentToken -> value ) ; } } else { $ formattedMessage = \ sprintf ( $ message , $ currentToken === null ? 'T_EOF' : $ currentToken -> type , $ currentToken === null ? 'end of stream' : $ currentToken -> value ) ; } throw new InvalidArgumentException ( $ formattedMessage ) ; }
Tests the current token to see if it matches the input type, and optionally the input value, and throws an
exception if the token did not match

@param string $type The type to check for
@param mixed $value The optional value to match against
@param string|null $message The exception message to use, otherwise a default one is generated
Any '%s' in the message is first populated with the expected type, and then with the expected value
@throws InvalidArgumentException Thrown if the current token didn't match the expected type and value
Tests the current token to see if it matches the input type and optionally the input value and throws an exception if the token did not match