| 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 ConditionalTypeForParameterNode implements TypeNode |
| 9: | { |
| 10: | |
| 11: | use NodeAttributes; |
| 12: | |
| 13: | |
| 14: | public $parameterName; |
| 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(string $parameterName, TypeNode $targetType, TypeNode $if, TypeNode $else, bool $negated) |
| 29: | { |
| 30: | $this->parameterName = $parameterName; |
| 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->parameterName, |
| 42: | $this->negated ? 'is not' : 'is', |
| 43: | $this->targetType, |
| 44: | $this->if, |
| 45: | $this->else |
| 46: | ); |
| 47: | } |
| 48: | |
| 49: | } |
| 50: | |