If_.php 1.4 KB

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