1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace PHPStan\Type\Generic; |
4: | |
5: | use function array_key_exists; |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | class TemplateTypeVarianceMap |
12: | { |
13: | |
14: | private static ?TemplateTypeVarianceMap $empty = null; |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | public function __construct(private array $variances) |
21: | { |
22: | } |
23: | |
24: | public static function createEmpty(): self |
25: | { |
26: | $empty = self::$empty; |
27: | |
28: | if ($empty !== null) { |
29: | return $empty; |
30: | } |
31: | |
32: | $empty = new self([]); |
33: | self::$empty = $empty; |
34: | |
35: | return $empty; |
36: | } |
37: | |
38: | |
39: | public function getVariances(): array |
40: | { |
41: | return $this->variances; |
42: | } |
43: | |
44: | public function hasVariance(string $name): bool |
45: | { |
46: | return array_key_exists($name, $this->getVariances()); |
47: | } |
48: | |
49: | public function getVariance(string $name): ?TemplateTypeVariance |
50: | { |
51: | return $this->getVariances()[$name] ?? null; |
52: | } |
53: | |
54: | } |
55: | |