final class SqlToken
Public API: explicitly declared with @visibility public.

One lexeme, with where it was written and how deeply it was nested.

The offset is what lets a rewriter put a statement back together around a token it wants to change, and the two depths are what let it tell a clause of the statement itself from the same words inside a subquery or a parenthesised list.

Inspect a token without losing its source offsetdoctest
$token = new \ZtdQuery\Sql\SqlToken(\ZtdQuery\Sql\SqlTokenKind::Word, 'SELECT', 2, 0, 0);
    $token->isKeyword('select') // => true
    $token->endOffset() // => 8
    $token->isTopLevel() // => true

Properties§

public string $text
public int $offset
public int $depth
public int $bracketDepth

Methods§

public function __construct(
    public SqlTokenKind $kind,
    public string $text,
    public int $offset,
    public int $depth,
    public int $bracketDepth,
)
public static function slice(
    string $sql,
    SqlTokenKind $kind,
    int $start,
    int $end,
    int $depth,
    int $bracketDepth,
): self

Answers the token a stretch of the statement was read as.

Parameters

$sqlstringThe statement, as written
$kindSqlTokenKindWhat kind of lexeme the stretch was read as
$startintWhere the lexeme starts
$endintWhere it ends, just past its last byte
$depthintHow many parentheses it is inside
$bracketDepthintHow many brackets it is inside

Returns

self The lexeme, carrying the text it was written as
Test cases 3
Called from 2
Calls 2
public function endOffset(): int

Answers where in the statement the lexeme ends.

Returns

int The offset just past its last byte
Test cases 1
Calls 1
public function isTopLevel(): bool

Reports whether the lexeme belongs to the statement itself.

Returns

bool True when it is inside no parenthesis and no bracket
Test cases 3
public function isKeyword(string $keyword): bool

Reports whether the lexeme is a given keyword.

SQL keywords are not case-sensitive, and neither is this.

Parameters

$keywordstringKeyword to test against

Returns

bool True when the lexeme is a word spelling that keyword
Test cases 3
Calls 2

Test cases 36§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 10
Other tests reaching this symbol 26

Relations§

Static calls 2
Type declarations 4