final class GenerationPlan<TRequiresNonEmpty of bool>
Public API: explicitly declared with @visibility public.

An immutable plan selecting the start rule, productions, lexemes and expansion limits. Plans can be reused without carrying mutable choice cursors between generations.

Keep a generation plan immutable and independent of earlier callsdoctest
$plan = \SqlFaker\Generation\Plan\GenerationPlan::all()->withExpansionBudget(100);
    $plan->expansionBudget() // => 100

Methods§

public function __construct(
    private non-empty-string|null $startRule,
    private array<string, non-empty-list<ProductionPattern>> $patterns,
    private array<string, ProductionPattern> $patternsForEveryOccurrence,
    private array<string, non-empty-list<string>> $lexemes,
    private non-empty-string|null $lexicalTarget,
    private array<string, int> $parameters,
    private TRequiresNonEmpty $requiresNonEmpty,
    private int $maxDepth,
    private bool $reserveSteps = false,
    private ?int $expansionBudget = null,
    private array<string, non-empty-list<string>> $candidateKeys = [],
)
Restricted visibility: declared "@visibility SqlFaker\Generation\Choice". Code outside that scope must not name this declaration.

Binds every choice a generation is directed by.

Parameters

$startRulenon-empty-string|nullRule the walk begins at, or null for the grammar entry point
$patternsarray<string, non-empty-list<ProductionPattern>>Patterns directing each occurrence of a rule
$patternsForEveryOccurrencearray<string, ProductionPattern>Pattern directing every further occurrence of a rule
$lexemesarray<string, non-empty-list<string>>Lexemes directing each occurrence of a terminal
$lexicalTargetnon-empty-string|nullLexical rule to realize instead of walking the grammar
$parametersarray<string, int>Parameters the lexical target is realized with
$requiresNonEmptyTRequiresNonEmptyWhether the walk must produce at least one symbol
$maxDepthint
$reserveStepsboolWhether to budget the remaining form and prefer fewer rule expansions
$expansionBudget?int
$candidateKeysarray<string, non-empty-list<string>>Exact candidate semantics by terminal occurrence
Test cases 25
public static function all(): self<false>

Directs a walk over the whole grammar from its own entry point.

Returns

self<false> Plan that constrains nothing
Test cases 74
Called from 3
Calls 1
public static function fromRule(string $startRule): self<false>

Directs a walk that begins at one rule instead of the grammar entry point.

Parameters

$startRulestringRule the walk begins at

Returns

self<false> Plan restricted to that rule

Throws

InvalidArgumentException When a required generation constraint is empty
Test cases 25
Called from 31
Calls 2
public static function constrained(
    string $startRule,
    array<string, non-empty-list<ProductionPattern>> $patterns,
): self<false>

Directs a walk that begins at one rule and takes the productions the caller named.

Parameters

$startRulestringRule the walk begins at
$patternsarray<string, non-empty-list<ProductionPattern>>Patterns directing each occurrence of a rule

Returns

self<false> Plan restricted to those productions

Throws

InvalidArgumentException When a required generation constraint is empty
Test cases 24
Called from 33
Calls 2
public static function lexical(string $target, array<string, int> $parameters): self<true>

Directs the realization of one lexical rule instead of a walk over the grammar.

Parameters

$targetstringLexical rule to realize
$parametersarray<string, int>Parameters the target is realized with

Returns

self<true> Plan that realizes that target

Throws

InvalidArgumentException When a required generation constraint is empty
Test cases 10
Called from 26
Calls 2
public function withLexemes(array<string, non-empty-list<string>> $lexemes): self<TRequiresNonEmpty>

Answers a plan that spells each occurrence of a terminal the way the caller asked.

Parameters

$lexemesarray<string, non-empty-list<string>>Lexemes directing each occurrence of a terminal

Returns

self<TRequiresNonEmpty> Plan carrying those lexemes

Throws

InvalidArgumentException When a required generation constraint is empty
Test cases 2
Calls 2
public function withMaxDepth(int $maxDepth): self<TRequiresNonEmpty>
public function startRule(): non-empty-string|null

Answers the rule the walk begins at.

Returns

non-empty-string|null Rule the walk begins at, or null for the grammar entry point
Test cases 17
Called from 3
public function patternAt(string $rule, int $occurrence): ProductionPattern|null

Answers the pattern directing one occurrence of a rule.

Parameters

$rulestringRule the walk has reached
$occurrenceintHow many times the walk has reached it before

Returns

ProductionPattern|null Pattern to take, or null when the walk may choose freely
Test cases 14
Called from 4
public function withPatternForEveryOccurrence(
    string $rule,
    ProductionPattern $pattern,
): self<TRequiresNonEmpty>

Answers a plan that directs every further occurrence of one rule the same way.

Parameters

$rulestringRule to direct
$patternProductionPatternPattern every occurrence not named directly takes

Returns

self<TRequiresNonEmpty> Plan carrying that fallback

Throws

InvalidArgumentException When a required generation constraint is empty
Test cases 6
Calls 2
public function withStepBudget(): self<TRequiresNonEmpty>

Reserves enough derivation steps to finish the entire remaining form.

Returns

self<TRequiresNonEmpty> Plan with a bounded completion policy
Test cases 1
Calls 1
public function usesStepBudget(): bool
public function withExpansionBudget(int $budget): self<TRequiresNonEmpty>

Bounds total expansions independently of the legacy depth policy.

Parameters

$budgetint

Returns

self<TRequiresNonEmpty>

Throws

InvalidArgumentException When no expansion is permitted
Test cases 1
Called from 1
Calls 2
public function withCandidateKeys(array<string, non-empty-list<string>> $keys): self<TRequiresNonEmpty>

Pins candidate semantics as well as spelling, including empty marker candidates.

Parameters

$keysarray<string, non-empty-list<string>>

Returns

self<TRequiresNonEmpty>
Test cases 2
Calls 1
public static function statement(non-empty-string|null $startRule, int $maxDepth): self<true>

Directs a bounded walk that must produce a statement.

Parameters

$startRulenon-empty-string|nullRule the statement is grown from, or null for the grammar entry point
$maxDepthint

Returns

self<true> Plan for one bounded, non-empty statement
Test cases 2
Called from 30
Calls 2

Private surface 11§

Implementation details, listed for orientation only.

private non-empty-string|null $startRule
private array<string, non-empty-list<ProductionPattern>> $patterns
private array<string, ProductionPattern> $patternsForEveryOccurrence
private array<string, non-empty-list<string>> $lexemes
private non-empty-string|null $lexicalTarget
private array<string, int> $parameters
private TRequiresNonEmpty $requiresNonEmpty
private int $maxDepth
private bool $reserveSteps = false
private ?int $expansionBudget = null
private array<string, non-empty-list<string>> $candidateKeys = []

Test cases 132§

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

Dedicated tests 33
Other tests reaching this symbol 99

Relations§

Instantiated in 1
Static calls 121
Method calls 37
Type declarations 110