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.

Reading an IF with ELSEdoctest
$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> $branches
public list<ProgramStatement|Statement> $otherwise

Methods§

public function __construct(
    list<ConditionalBranch> $branches,
    list<ProgramStatement|Statement> $otherwise = [],
)

Parameters

$brancheslist<ConditionalBranch>The IF branch and the ELSEIF branches; at least one
$otherwiselist<ProgramStatement|Statement>The statements of ELSE; empty without ELSE

Throws

InvalidConstruction When there is no branch or a member is of another class
Calls 4
public function deriveProgram(Derivation $derivation, ProgramScope $scope): void

Derives the conditions and the statements of every branch.

Parameters

$derivationDerivation
$scopeProgramScope
Calls 2
public function render(Output $out): void

Writes the statement.

Parameters

$outOutput
Calls 3

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

Relations§

Instantiated in 1
Type checks 1
Type declarations 1