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