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