Ternary.php 967 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Expr;
  3. use PhpParser\Node\Expr;
  4. class Ternary extends Expr {
  5. /** @var Expr Condition */
  6. public Expr $cond;
  7. /** @var null|Expr Expression for true */
  8. public ?Expr $if;
  9. /** @var Expr Expression for false */
  10. public Expr $else;
  11. /**
  12. * Constructs a ternary operator node.
  13. *
  14. * @param Expr $cond Condition
  15. * @param null|Expr $if Expression for true
  16. * @param Expr $else Expression for false
  17. * @param array<string, mixed> $attributes Additional attributes
  18. */
  19. public function __construct(Expr $cond, ?Expr $if, Expr $else, array $attributes = []) {
  20. $this->attributes = $attributes;
  21. $this->cond = $cond;
  22. $this->if = $if;
  23. $this->else = $else;
  24. }
  25. public function getSubNodeNames(): array {
  26. return ['cond', 'if', 'else'];
  27. }
  28. public function getType(): string {
  29. return 'Expr_Ternary';
  30. }
  31. }