classRulePlan
final class RulePlan
Public API: explicitly declared with
@visibility public.Conditions on a grammar subtree; nested conditions use grammar roles rather than global occurrence numbers.
$pattern = \SqlFaker\Generation\Plan\ProductionPattern::containing('SELECT');
$plan = \SqlFaker\Generation\Plan\RulePlan::any()->allowing($pattern);
$plan->pattern?->matches(['SELECT', 'expr']) // => trueProperties§
public ?ProductionPattern $pattern = nullpublic array<string, self> $rules = []public array<string, LexemeConstraint> $lexemes = []public non-empty-list<self>|null $items = nullpublic array<string, array<int, self>> $children = []Methods§
public function __construct(
public ?ProductionPattern $pattern = null,
public array<string, self> $rules = [],
public array<string, LexemeConstraint> $lexemes = [],
public non-empty-list<self>|null $items = null,
public array<string, array<int, self>> $children = [],
)Parameters
$pattern | ?ProductionPattern | |
$rules | array<string, self> | Descendant scopes, with nearer scopes taking precedence |
$lexemes | array<string, LexemeConstraint> | Token domains inside this scope |
$items | non-empty-list<self>|null | Ordered items of a directly recursive grammar list |
$children | array<string, array<int, self>> | Conditions on direct children, counted separately per production |
public static function any(): selfLeaves every alternative available until conditions are added.
Returns
selfTest cases 32
PlanBuilderTest::testBuildFreezesScopedValuesAndDefaultsWhenChoiceBytesRunOutcallsTokenGeneratorTest::testDeriveRetainsOriginalRuleIdentityForRepeatedChoicescallsTokenGeneratorTest::testMinimumExpansionsIncludesEveryPlannedListItemcallsTokenGeneratorTest::testMinimumExpansionsUsesTheCurrentRootPlanAndExplicitBudgetcallsTokenGeneratorTest::testPrepareKeepsPlansAndUnconstrainedCallsIndependentcallsGrammarCompilerTest::testCompileAppliesProductionConditionsToEachListItemcallsGrammarCompilerTest::testCompileContradictoryProductionConditionsAreRejectedcallsGrammarCompilerTest::testCompileListItemsPreserveOutputOrderForBothRecursionDirectionscallsGrammarCompilerTest::testHasChildrenConditionsPruneIncompatibleProductionscallsGrammarCompilerTest::testHasChildrenRejectsARequiredRoleAbsentFromTheProductioncallsGrammarCompilerTest::testItemRejectsNullableAndBranchingRecursionForOrderedListscallsGrammarCompilerTest::testItemSupportsUnseparatedListsButRejectsRecursionBetweenFieldscallsGrammarCompilerTest::testSymbolsApplyChildConditionsToARecursiveListTailcallsGrammarCompilerTest::testSymbolsKeepInfeasibleBranchesFromInvalidatingOtherAlternativescallsGrammarCompilerTest::testSymbolsPreserveInheritedRulesWhenSelectingAnOperandcallsGrammarCompilerTest::testValidateAcceptsNestedChildAndListDeclarationscallsScopeTest::testEnterNearerScopesOverrideDefaultsWithoutLeakingToSiblingscallsScopeTest::testEnterOverridesOnlyDeclaredRolesAndCanonicalizesIndependentDeclarationOrdercallsGenerationPlanTest::testRefineCanClearOptionalInstructionsWhilePreservingOtherSettingscallsGenerationPlanTest::testRulesExposeMergedConditionsWithoutMutatingTheOriginalcallsGenerationPlanTest::testWithRuleConditionsSurviveEveryImmutableModifiercallsRulePlanTest::testAllowingRefinementsIntersectAndLeaveTheOriginalPlanIntactcallsRulePlanTest::testAnyLeavesEveryKindOfChoiceUnspecifiedcallsRulePlanTest::testMergeCombinesNestedRulesAndPreservesIndependentBindingscallsRulePlanTest::testMergeIntersectsCorrespondingListItemscallsRulePlanTest::testWithChildIntersectsOnlyTheSelectedOperandcallsRulePlanTest::testWithItemsAcceptsNamedArgumentsAndKeepsEveryItemInOrdercallsRulePlanTest::testWithItemsRetainsHeterogeneousOutputOrdercallsRulePlanTest::testWithLexemeIntersectsDomainsWithoutChangingOtherTokenscallsRulePlanTest::testWithRuleMergingPreservesChildAndListRelationshipscallsMySqlProviderTest::providerScopedInsertPlancallsPostgreSqlProviderTest::providerScopedInsertPlancalls
Called from 1
Calls 1
- new
selfline 40
public function allowing(ProductionPattern $pattern): selfAdds a condition on the root production without specifying descendants.
Parameters
$pattern | ProductionPattern |
Returns
selfCalled from 1
Calls 2
- new
selfline 48 - static-call ProductionPattern::allOf() line 48
public function withRule(string $rule, self $plan): selfApplies a plan whenever the named descendant rule is reached in this scope.
Parameters
$rule | string | |
$plan | self |
Returns
selfThrows
InvalidArgumentException When the rule name is empty or its conditions conflictCalled from 1
public function withChild(string $rule, int $index, self $plan): selfpublic function withLexeme(string $terminal, LexemeConstraint $constraint): selfConstrains every matching terminal in this scope, independently of sibling scopes.
Parameters
$terminal | string | |
$constraint | LexemeConstraint |
Returns
selfThrows
InvalidArgumentException When the terminal is empty or domains are disjointpublic function withItems(self $first, self ...$others): selfSpecifies list items in output order while retaining compatible list productions. Each item constrains the non-recursive portion of one production of the list.
Parameters
$first | self | |
$others | self |
Returns
selfThrows
InvalidArgumentException When two list conditions disagreeCalls 3
- method-call RulePlan::merge() line 100
- new
selfline 100 - function-call
array_valuesline 100
public function merge(self $other): selfCombines conditions at the same scope by intersection, never by silently replacing them.
Parameters
$other | self |
Returns
selfThrows
InvalidArgumentException When lexical domains or list lengths conflictCalled from 1
Calls 4
- method-call RulePlan::allowing() line 109
- function-call
countline 123 - new
InvalidArgumentExceptionline 124 - new
selfline 131
Test cases 32§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 9
RulePlanTest::testAllowingRefinementsIntersectAndLeaveTheOriginalPlanIntactcallsRulePlanTest::testAnyLeavesEveryKindOfChoiceUnspecifiedcallsRulePlanTest::testMergeCombinesNestedRulesAndPreservesIndependentBindingscallsRulePlanTest::testMergeIntersectsCorrespondingListItemscallsRulePlanTest::testWithChildIntersectsOnlyTheSelectedOperandcallsRulePlanTest::testWithItemsAcceptsNamedArgumentsAndKeepsEveryItemInOrdercallsRulePlanTest::testWithItemsRetainsHeterogeneousOutputOrdercallsRulePlanTest::testWithLexemeIntersectsDomainsWithoutChangingOtherTokenscallsRulePlanTest::testWithRuleMergingPreservesChildAndListRelationshipscalls
Other tests reaching this symbol 23
PlanBuilderTest::testBuildFreezesScopedValuesAndDefaultsWhenChoiceBytesRunOutcallsTokenGeneratorTest::testDeriveRetainsOriginalRuleIdentityForRepeatedChoicescallsTokenGeneratorTest::testMinimumExpansionsIncludesEveryPlannedListItemcallsTokenGeneratorTest::testMinimumExpansionsUsesTheCurrentRootPlanAndExplicitBudgetcallsTokenGeneratorTest::testPrepareKeepsPlansAndUnconstrainedCallsIndependentcallsGrammarCompilerTest::testCompileAppliesProductionConditionsToEachListItemcallsGrammarCompilerTest::testCompileContradictoryProductionConditionsAreRejectedcallsGrammarCompilerTest::testCompileListItemsPreserveOutputOrderForBothRecursionDirectionscallsGrammarCompilerTest::testHasChildrenConditionsPruneIncompatibleProductionscallsGrammarCompilerTest::testHasChildrenRejectsARequiredRoleAbsentFromTheProductioncallsGrammarCompilerTest::testItemRejectsNullableAndBranchingRecursionForOrderedListscallsGrammarCompilerTest::testItemSupportsUnseparatedListsButRejectsRecursionBetweenFieldscallsGrammarCompilerTest::testSymbolsApplyChildConditionsToARecursiveListTailcallsGrammarCompilerTest::testSymbolsKeepInfeasibleBranchesFromInvalidatingOtherAlternativescallsGrammarCompilerTest::testSymbolsPreserveInheritedRulesWhenSelectingAnOperandcallsGrammarCompilerTest::testValidateAcceptsNestedChildAndListDeclarationscallsScopeTest::testEnterNearerScopesOverrideDefaultsWithoutLeakingToSiblingscallsScopeTest::testEnterOverridesOnlyDeclaredRolesAndCanonicalizesIndependentDeclarationOrdercallsGenerationPlanTest::testRefineCanClearOptionalInstructionsWhilePreservingOtherSettingscallsGenerationPlanTest::testRulesExposeMergedConditionsWithoutMutatingTheOriginalcallsGenerationPlanTest::testWithRuleConditionsSurviveEveryImmutableModifiercallsMySqlProviderTest::providerScopedInsertPlancallsPostgreSqlProviderTest::providerScopedInsertPlancalls
Relations§
Instantiated in 1
Static calls 1
Method calls 1
Type declarations 3
- type SqlFaker\Generation\Plan\Compilation\GrammarCompiler packages/sql-faker/src/Generation/Plan/Compilation/GrammarCompiler.php:122
- type SqlFaker\Generation\Plan\Compilation\Scope packages/sql-faker/src/Generation/Plan/Compilation/Scope.php:26
- type SqlFaker\Generation\Plan\GenerationPlan packages/sql-faker/src/Generation/Plan/GenerationPlan.php:162