classIfStatement
final class IfStatement
implements ProgramStatement
uses Snapshot
Public API: explicitly declared with
@visibility public.IF ... THEN ... ELSEIF ... ELSE ... END IF.
The first branch is the IF, every further branch an ELSEIF. The facts follow MYSQL-PROGRAM-FLOW-001. Source: https://dev.mysql.com/doc/refman/8.4/en/if.html.
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE PROCEDURE p(a INT) IF a THEN SELECT 1; ELSE SELECT 2; END IF');
[count($create->statement->body->branches), count($create->statement->body->otherwise)] // => [1, 1]Properties§
public non-empty-list<ConditionalBranch> $branchespublic list<ProgramStatement|Statement> $otherwiseMethods§
public function __construct(
list<ConditionalBranch> $branches,
list<ProgramStatement|Statement> $otherwise = [],
)Parameters
$branches | list<ConditionalBranch> | The IF branch and the ELSEIF branches; at least one |
$otherwise | list<ProgramStatement|Statement> | The statements of ELSE; empty without ELSE |
Throws
InvalidConstruction When there is no branch or a member is of another classCalls 4
- static-call Check::listOf() line 51
- class-const ConditionalBranch::class() line 51
- method-call StatementSequence::members() line 52
- new StatementSequence line 52
public function deriveProgram(Derivation $derivation, ProgramScope $scope): voidDerives the conditions and the statements of every branch.
Parameters
$derivation | Derivation | |
$scope | ProgramScope |
Calls 2
- method-call FlowFacts::branches() line 60
- new FlowFacts line 60
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 3
- method-call Output::keyword() line 69
- method-call StatementSequence::write() line 73
- new StatementSequence line 73
Test cases 13§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 2
Other tests reaching this symbol 11
FlowRuleTest::testConditionalLowersAnIfWithoutElsecallsFlowRuleTest::testConditionalLowersTheBranchesAndTheElsecallsFlowRuleTest::testJumpLowersReturnLeaveAndIteratecallsStatementRuleTest::providerEventLowersTheStatementOfAnEventcallsStatementRuleTest::testStatementRoutesEveryKindOfProgramStatementcallsFlowFactsTest::testBranchesResolvesAVariableInTheConditioncallsReturnSearchTest::providerFoundFindsANestedReturncallsReturnSearchTest::providerFoundIsFalseWithoutReturncallsReturnSearchTest::testNestedAnswersTheElseStatementsBeforeTheBranchStatementscallsConditionalBranchTest::testRenderWritesTheConditionAndTheStatementscallsProgramStatementTest::providerDeriveProgramIsImplementedByTheProgramStatementClassescalls