HEX
Server: Apache
System: Linux WWW 6.1.0-40-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.153-1 (2025-09-20) x86_64
User: web11 (1011)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/payments-gateway/vendor/doctrine/sql-formatter/src/Cursor.php
<?php

declare(strict_types=1);

namespace Doctrine\SqlFormatter;

final class Cursor
{
    private int $position = -1;

    /** @param list<Token> $tokens */
    public function __construct(
        private readonly array $tokens,
    ) {
    }

    /** @param Token::TOKEN_TYPE_* $exceptTokenType */
    public function next(int|null $exceptTokenType = null): Token|null
    {
        while ($token = $this->tokens[++$this->position] ?? null) {
            if ($exceptTokenType !== null && $token->isOfType($exceptTokenType)) {
                continue;
            }

            return $token;
        }

        return null;
    }

    /** @param Token::TOKEN_TYPE_* $exceptTokenType */
    public function previous(int|null $exceptTokenType = null): Token|null
    {
        while ($token = $this->tokens[--$this->position] ?? null) {
            if ($exceptTokenType !== null && $token->isOfType($exceptTokenType)) {
                continue;
            }

            return $token;
        }

        return null;
    }

    public function subCursor(): self
    {
        $cursor           = new self($this->tokens);
        $cursor->position = $this->position;

        return $cursor;
    }
}