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: /** @api */
10: class ConstantArrayTypeAndMethod
11: {
12:
13: private function __construct(
14: private ?Type $type,
15: private ?string $method,
16: private TrinaryLogic $certainty,
17: )
18: {
19: }
20:
21: public static function createConcrete(
22: Type $type,
23: string $method,
24: TrinaryLogic $certainty,
25: ): self
26: {
27: if ($certainty->no()) {
28: throw new ShouldNotHappenException();
29: }
30: return new self($type, $method, $certainty);
31: }
32:
33: public static function createUnknown(): self
34: {
35: return new self(null, null, TrinaryLogic::createMaybe());
36: }
37:
38: public function isUnknown(): bool
39: {
40: return $this->type === null;
41: }
42:
43: public function getType(): Type
44: {
45: if ($this->type === null) {
46: throw new ShouldNotHappenException();
47: }
48:
49: return $this->type;
50: }
51:
52: public function getMethod(): string
53: {
54: if ($this->method === null) {
55: throw new ShouldNotHappenException();
56: }
57:
58: return $this->method;
59: }
60:
61: public function getCertainty(): TrinaryLogic
62: {
63: return $this->certainty;
64: }
65:
66: }
67: