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