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: | |
14: | public $subjectType; |
15: | |
16: | |
17: | public $targetType; |
18: | |
19: | |
20: | public $if; |
21: | |
22: | |
23: | public $else; |
24: | |
25: | |
26: | public $negated; |
27: | |
28: | public function __construct(TypeNode $subjectType, TypeNode $targetType, TypeNode $if, TypeNode $else, bool $negated) |
29: | { |
30: | $this->subjectType = $subjectType; |
31: | $this->targetType = $targetType; |
32: | $this->if = $if; |
33: | $this->else = $else; |
34: | $this->negated = $negated; |
35: | } |
36: | |
37: | public function __toString(): string |
38: | { |
39: | return sprintf( |
40: | '(%s %s %s ? %s : %s)', |
41: | $this->subjectType, |
42: | $this->negated ? 'is not' : 'is', |
43: | $this->targetType, |
44: | $this->if, |
45: | $this->else |
46: | ); |
47: | } |
48: | |
49: | } |
50: | |