1: <?php declare(strict_types=1);
2:
3: namespace PhpParser\Node\Stmt;
4:
5: use PhpParser\Node;
6:
7: class If_ extends Node\Stmt {
8: /** @var Node\Expr Condition expression */
9: public Node\Expr $cond;
10: /** @var Node\Stmt[] Statements */
11: public array $stmts;
12: /** @var ElseIf_[] Elseif clauses */
13: public array $elseifs;
14: /** @var null|Else_ Else clause */
15: public ?Else_ $else;
16:
17: /**
18: * Constructs an if node.
19: *
20: * @param Node\Expr $cond Condition
21: * @param array{
22: * stmts?: Node\Stmt[],
23: * elseifs?: ElseIf_[],
24: * else?: Else_|null,
25: * } $subNodes Array of the following optional subnodes:
26: * 'stmts' => array(): Statements
27: * 'elseifs' => array(): Elseif clauses
28: * 'else' => null : Else clause
29: * @param array<string, mixed> $attributes Additional attributes
30: */
31: public function __construct(Node\Expr $cond, array $subNodes = [], array $attributes = []) {
32: $this->attributes = $attributes;
33: $this->cond = $cond;
34: $this->stmts = $subNodes['stmts'] ?? [];
35: $this->elseifs = $subNodes['elseifs'] ?? [];
36: $this->else = $subNodes['else'] ?? null;
37: }
38:
39: public function getSubNodeNames(): array {
40: return ['cond', 'stmts', 'elseifs', 'else'];
41: }
42:
43: public function getType(): string {
44: return 'Stmt_If';
45: }
46: }
47: