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