| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Type; |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | final class GeneralizePrecision |
| 26: | { |
| 27: | |
| 28: | private const LESS_SPECIFIC = 1; |
| 29: | private const MORE_SPECIFIC = 2; |
| 30: | private const TEMPLATE_ARGUMENT = 3; |
| 31: | |
| 32: | |
| 33: | private static array $registry; |
| 34: | |
| 35: | private function __construct(private int $value) |
| 36: | { |
| 37: | } |
| 38: | |
| 39: | private static function create(int $value): self |
| 40: | { |
| 41: | self::$registry[$value] ??= new self($value); |
| 42: | return self::$registry[$value]; |
| 43: | } |
| 44: | |
| 45: | |
| 46: | public static function lessSpecific(): self |
| 47: | { |
| 48: | return self::create(self::LESS_SPECIFIC); |
| 49: | } |
| 50: | |
| 51: | |
| 52: | public static function moreSpecific(): self |
| 53: | { |
| 54: | return self::create(self::MORE_SPECIFIC); |
| 55: | } |
| 56: | |
| 57: | |
| 58: | public static function templateArgument(): self |
| 59: | { |
| 60: | return self::create(self::TEMPLATE_ARGUMENT); |
| 61: | } |
| 62: | |
| 63: | public function isMoreSpecific(): bool |
| 64: | { |
| 65: | return $this->value === self::MORE_SPECIFIC; |
| 66: | } |
| 67: | |
| 68: | public function isTemplateArgument(): bool |
| 69: | { |
| 70: | return $this->value === self::TEMPLATE_ARGUMENT; |
| 71: | } |
| 72: | |
| 73: | } |
| 74: | |