1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Reflection;
4:
5: use function array_key_exists;
6:
7: /**
8: * @api
9: * @final
10: */
11: class PassedByReference
12: {
13:
14: private const NO = 1;
15: private const READS_ARGUMENT = 2;
16: private const CREATES_NEW_VARIABLE = 3;
17:
18: /** @var self[] */
19: private static array $registry = [];
20:
21: private function __construct(private int $value)
22: {
23: }
24:
25: private static function create(int $value): self
26: {
27: if (!array_key_exists($value, self::$registry)) {
28: self::$registry[$value] = new self($value);
29: }
30:
31: return self::$registry[$value];
32: }
33:
34: public static function createNo(): self
35: {
36: return self::create(self::NO);
37: }
38:
39: public static function createCreatesNewVariable(): self
40: {
41: return self::create(self::CREATES_NEW_VARIABLE);
42: }
43:
44: public static function createReadsArgument(): self
45: {
46: return self::create(self::READS_ARGUMENT);
47: }
48:
49: public function no(): bool
50: {
51: return $this->value === self::NO;
52: }
53:
54: public function yes(): bool
55: {
56: return !$this->no();
57: }
58:
59: public function equals(self $other): bool
60: {
61: return $this->value === $other->value;
62: }
63:
64: public function createsNewVariable(): bool
65: {
66: return $this->value === self::CREATES_NEW_VARIABLE;
67: }
68:
69: public function combine(self $other): self
70: {
71: if ($this->value > $other->value) {
72: return $this;
73: } elseif ($this->value < $other->value) {
74: return $other;
75: }
76:
77: return $this;
78: }
79:
80: /**
81: * @param mixed[] $properties
82: */
83: public static function __set_state(array $properties): self
84: {
85: return new self($properties['value']);
86: }
87:
88: }
89: