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

Observes derivations without influencing generation or consuming randomness.

Type Aliases§

Checkpoint = array{savedAt: string, runId: string, generationsObservedInRun: int, generationInProgress: bool}
History = array{formatVersion: int, grammarFingerprint: string, generatorRevision: string, root: string, inventoryDigest: string, cumulative: array{reachedIds: list<string>, emittedIds: list<string>}, checkpoint: Checkpoint}
Snapshot = array{formatVersion: int, grammarFingerprint: string, generatorRevision: string, root: string, inventoryDigest: string, denominatorIds: list<string>, inventory: array<string, Entry>, adaptations: list<array{origin: string, status: string}>, current: Measurement, cumulative: Measurement, checkpoint: Checkpoint, restoredCheckpoint: Checkpoint|null}
Measurement = import from CoverageSets
Trace = import from GenerationTrace
Entry = import from GrammarCoverageInventory
Begin memory-only grammar measurementdoctest
$coverage = new \SqlFaker\Generation\Coverage\GrammarCoverage();
    $coverage->lastGeneration() // => null

Constants§

public const FLUSH_INTERVAL = 100

Number of generations after which unsaved discoveries are written to the snapshot directory.

Methods§

public function __construct(private ?string $storageDirectory = null)

Enables memory-only measurement unless a snapshot directory is explicitly supplied.

A supplied directory is written every FLUSH_INTERVAL generations and once more at shutdown, so callers only decide whether coverage is recorded.

Parameters

$storageDirectory?string
Test cases 23
Calls 6
public function register(GrammarCoverageInventory $inventory, string $revision): void

Registers the full inventory and restores compatible history exactly once.

Parameters

$inventoryGrammarCoverageInventory
$revisionstring

Throws

CoverageException When already registered to an incompatible generator
Test cases 28
Calls 3
public function restore(): void
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

Restores only after compatibility identity is known; failed setup remains retryable.

Throws

CoverageException When history is corrupt, incompatible or inaccessible
Test cases 22
Called from 1
Calls 6
public function inventory(): GrammarCoverageInventory

Returns the full denominator, including alternatives never observed.

Throws

CoverageException When not attached to a provider
Test cases 24
Called from 4
Calls 1
public function beginGeneration(
    string $root,
    array<string, int|string|bool|null> $planSummary,
): void

Begins a generation and replaces even the previous successful trace.

Parameters

$rootstring
$planSummaryarray<string, int|string|bool|null>
Test cases 19
Calls 1
public function beginAttempt(int $id): void

Begins one lexical realization attempt.

Parameters

$idint
Test cases 17
public function record(
    int $node,
    ?int $parent,
    ?int $position,
    string $rule,
    string $production,
    string $reason,
): void

Records an occurrence immediately after production selection.

Parameters

$nodeint
$parent?int
$position?int
$rulestring
$productionstring
$reasonstring
Test cases 16
Called from 1
public function recordSequence(TerminalSequence $sequence): void

Records original grammar choices even when a rewrite replaces their entire output.

Parameters

Test cases 1
Calls 6
public function recordOutput(ResolvedOutput $output): void

Exposes chosen compound candidates and the boundary rules used in the final output.

Parameters

Test cases 1
Calls 5
public function commitAttempt(string $sqlHash, list<int>|null $nodes = null): void

Adds only preserved source productions from the successful attempt to emitted coverage.

Parameters

$sqlHashstring
$nodeslist<int>|nullPreserved occurrence IDs, or null for an unmodified derivation
Test cases 15
public function endGeneration(): void

Closes the generation in a finally block, retaining failures, and saves every FLUSH_INTERVAL generations.

Throws

CoverageException When a snapshot cannot be encoded
Test cases 16
Calls 2
public function lastGeneration(): Trace|null

Returns the latest generation only; no full-run trace is accumulated.

Returns

Trace|null
Test cases 16
public function snapshot(): Snapshot

Reads named current and cumulative sets without performing file I/O.

Returns

Test cases 26
Called from 2
Calls 3

Private surface 12§

Implementation details, listed for orientation only.

private ?GrammarCoverageInventory $inventory = null
private string $revision = ''
private CoverageSets $saved
private CoverageSets $current
private ?GenerationTrace $trace = null
private ?CoverageSnapshotStore $store = null
private bool $dirty = false
private bool $inProgress = false
private int $generations = 0
private string $runId
private Checkpoint|null $restoredCheckpoint = null
private ?string $storageDirectory = null

Test cases 37§

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

Dedicated tests 23
Other tests reaching this symbol 14

Relations§

Type declarations 7