| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Type\Constant; |
| 4: | |
| 5: | use PHPStan\ShouldNotHappenException; |
| 6: | use PHPStan\TrinaryLogic; |
| 7: | use PHPStan\Type\Type; |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | class ConstantArrayTypeAndMethod |
| 14: | { |
| 15: | |
| 16: | private function __construct( |
| 17: | private ?Type $type, |
| 18: | private ?string $method, |
| 19: | private TrinaryLogic $certainty, |
| 20: | ) |
| 21: | { |
| 22: | } |
| 23: | |
| 24: | public static function createConcrete( |
| 25: | Type $type, |
| 26: | string $method, |
| 27: | TrinaryLogic $certainty, |
| 28: | ): self |
| 29: | { |
| 30: | if ($certainty->no()) { |
| 31: | throw new ShouldNotHappenException(); |
| 32: | } |
| 33: | return new self($type, $method, $certainty); |
| 34: | } |
| 35: | |
| 36: | public static function createUnknown(): self |
| 37: | { |
| 38: | return new self(null, null, TrinaryLogic::createMaybe()); |
| 39: | } |
| 40: | |
| 41: | public function isUnknown(): bool |
| 42: | { |
| 43: | return $this->type === null; |
| 44: | } |
| 45: | |
| 46: | public function getType(): Type |
| 47: | { |
| 48: | if ($this->type === null) { |
| 49: | throw new ShouldNotHappenException(); |
| 50: | } |
| 51: | |
| 52: | return $this->type; |
| 53: | } |
| 54: | |
| 55: | public function getMethod(): string |
| 56: | { |
| 57: | if ($this->method === null) { |
| 58: | throw new ShouldNotHappenException(); |
| 59: | } |
| 60: | |
| 61: | return $this->method; |
| 62: | } |
| 63: | |
| 64: | public function getCertainty(): TrinaryLogic |
| 65: | { |
| 66: | return $this->certainty; |
| 67: | } |
| 68: | |
| 69: | } |
| 70: | |