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