1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\PhpDocParser\Ast\Type;
4:
5: use PHPStan\PhpDocParser\Ast\NodeAttributes;
6: use function sprintf;
7:
8: class ConditionalTypeNode implements TypeNode
9: {
10:
11: use NodeAttributes;
12:
13: public TypeNode $subjectType;
14:
15: public TypeNode $targetType;
16:
17: public TypeNode $if;
18:
19: public TypeNode $else;
20:
21: public bool $negated;
22:
23: public function __construct(TypeNode $subjectType, TypeNode $targetType, TypeNode $if, TypeNode $else, bool $negated)
24: {
25: $this->subjectType = $subjectType;
26: $this->targetType = $targetType;
27: $this->if = $if;
28: $this->else = $else;
29: $this->negated = $negated;
30: }
31:
32: public function __toString(): string
33: {
34: return sprintf(
35: '(%s %s %s ? %s : %s)',
36: $this->subjectType,
37: $this->negated ? 'is not' : 'is',
38: $this->targetType,
39: $this->if,
40: $this->else,
41: );
42: }
43:
44: }
45: