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