classConditionalBranch
final class ConditionalBranch
implements Node
uses Snapshot
Public API: explicitly declared with
@visibility public.One branch of IF or CASE: an expression, THEN, and the statements that run when the branch is chosen.
In IF and in a searched CASE the expression is a search condition; in a simple CASE it is the value compared with the operand of the CASE. Source: https://dev.mysql.com/doc/refman/8.4/en/if.html, https://dev.mysql.com/doc/refman/8.4/en/case.html.
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE PROCEDURE p(a INT) IF a = 1 THEN SELECT 1; ELSEIF a = 2 THEN SELECT 2; SELECT 3; END IF');
[count($create->statement->body->branches), count($create->statement->body->branches[1]->statements)] // => [2, 2]Properties§
public non-empty-list<ProgramStatement|Statement> $statementspublic Scalar $conditionMethods§
public function __construct(
public Scalar $condition,
list<ProgramStatement|Statement> $statements,
)Parameters
$condition | Scalar | The search condition, or the compared value of a simple CASE |
$statements | list<ProgramStatement|Statement> | The statements after THEN; at least one |
Throws
InvalidConstruction When there is no statement or a member is of another classCalls 2
- method-call StatementSequence::members() line 45
- new StatementSequence line 45
public function render(Output $out): voidWrites the expression, THEN and the statements.
Parameters
$out | Output |
Calls 3
- method-call Output::node() line 53
- method-call StatementSequence::write() line 54
- new StatementSequence line 54
Test cases 9§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
Other tests reaching this symbol 8
FlowRuleTest::testChoiceLowersASearchedCasecallsFlowRuleTest::testChoiceLowersASimpleCasecallsFlowRuleTest::testConditionalLowersAnIfWithoutElsecallsFlowRuleTest::testJumpLowersReturnLeaveAndIteratecallsReturnSearchTest::providerFoundFindsANestedReturncallsReturnSearchTest::providerFoundIsFalseWithoutReturncallsReturnSearchTest::testNestedAnswersTheElseStatementsBeforeTheBranchStatementscallsProgramStatementTest::providerDeriveProgramIsImplementedByTheProgramStatementClassescalls
Relations§
Instantiated in 2
- new SqlSemantics\Platform\MySql\Lowering\Routine\Program\FlowRule::conditional() packages/sql-semantics-mysql/src/Lowering/Routine/Program/FlowRule.php:79
- new SqlSemantics\Platform\MySql\Lowering\Routine\Program\FlowRule::choice() packages/sql-semantics-mysql/src/Lowering/Routine/Program/FlowRule.php:115
Constant reads 3
- class-const SqlSemantics\Platform\MySql\Statement\Routine\Program\Flow\IfStatement::__construct() packages/sql-semantics-mysql/src/Statement/Routine/Program/Flow/IfStatement.php:51
- class-const SqlSemantics\Platform\MySql\Statement\Routine\Program\Flow\SearchedCase::__construct() packages/sql-semantics-mysql/src/Statement/Routine/Program/Flow/SearchedCase.php:50
- class-const SqlSemantics\Platform\MySql\Statement\Routine\Program\Flow\SimpleCase::__construct() packages/sql-semantics-mysql/src/Statement/Routine/Program/Flow/SimpleCase.php:54