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