@@ -31,6 +31,7 @@ abstract class Enum implements \JsonSerializable
31
31
/**
32
32
* Store existing constants in a static cache per object.
33
33
*
34
+ *
34
35
* @var array
35
36
* @psalm-var array<class-string, array<string, mixed>>
36
37
*/
@@ -39,26 +40,30 @@ abstract class Enum implements \JsonSerializable
39
40
/**
40
41
* Creates a new value of some type
41
42
*
43
+ * @psalm-pure
42
44
* @param mixed $value
43
45
*
44
- * @psalm-param T $value
45
- * @psalm-suppress InvalidCast
46
+ * @psalm-param static<T>|T $value
46
47
* @throws \UnexpectedValueException if incompatible type is given.
47
48
*/
48
49
public function __construct ($ value )
49
50
{
50
51
if ($ value instanceof static) {
52
+ /** @psalm-var T */
51
53
$ value = $ value ->getValue ();
52
54
}
53
55
54
56
if (!$ this ->isValid ($ value )) {
57
+ /** @psalm-suppress InvalidCast */
55
58
throw new \UnexpectedValueException ("Value ' $ value' is not part of the enum " . static ::class);
56
59
}
57
60
61
+ /** @psalm-var T */
58
62
$ this ->value = $ value ;
59
63
}
60
64
61
65
/**
66
+ * @psalm-pure
62
67
* @return mixed
63
68
* @psalm-return T
64
69
*/
@@ -79,6 +84,7 @@ public function getKey()
79
84
}
80
85
81
86
/**
87
+ * @psalm-pure
82
88
* @psalm-suppress InvalidCast
83
89
* @return string
84
90
*/
@@ -93,6 +99,7 @@ public function __toString()
93
99
*
94
100
* This method is final, for more information read https://github.com/myclabs/php-enum/issues/4
95
101
*
102
+ * @psalm-pure
96
103
* @psalm-param mixed $variable
97
104
* @return bool
98
105
*/
@@ -106,6 +113,8 @@ final public function equals($variable = null): bool
106
113
/**
107
114
* Returns the names (keys) of all constants in the Enum class
108
115
*
116
+ * @psalm-pure
117
+ * @psalm-return list<string>
109
118
* @return array
110
119
*/
111
120
public static function keys ()
@@ -116,12 +125,15 @@ public static function keys()
116
125
/**
117
126
* Returns instances of the Enum class of all Enum constants
118
127
*
128
+ * @psalm-pure
129
+ * @psalm-return array<string, static>
119
130
* @return static[] Constant name in key, Enum instance in value
120
131
*/
121
132
public static function values ()
122
133
{
123
134
$ values = array ();
124
135
136
+ /** @psalm-var T $value */
125
137
foreach (static ::toArray () as $ key => $ value ) {
126
138
$ values [$ key ] = new static ($ value );
127
139
}
@@ -133,6 +145,8 @@ public static function values()
133
145
* Returns all possible values as an array
134
146
*
135
147
* @psalm-pure
148
+ * @psalm-suppress ImpureStaticProperty
149
+ *
136
150
* @psalm-return array<string, mixed>
137
151
* @return array Constant name in key, constant value in value
138
152
*/
@@ -153,7 +167,7 @@ public static function toArray()
153
167
*
154
168
* @param $value
155
169
* @psalm-param mixed $value
156
- *
170
+ * @psalm-pure
157
171
* @return bool
158
172
*/
159
173
public static function isValid ($ value )
@@ -166,7 +180,7 @@ public static function isValid($value)
166
180
*
167
181
* @param $key
168
182
* @psalm-param string $key
169
- *
183
+ * @psalm-pure
170
184
* @return bool
171
185
*/
172
186
public static function isValidKey ($ key )
@@ -197,6 +211,7 @@ public static function search($value)
197
211
* @param array $arguments
198
212
*
199
213
* @return static
214
+ * @psalm-pure
200
215
* @throws \BadMethodCallException
201
216
*/
202
217
public static function __callStatic ($ name , $ arguments )
@@ -215,6 +230,7 @@ public static function __callStatic($name, $arguments)
215
230
*
216
231
* @return mixed
217
232
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
233
+ * @psalm-pure
218
234
*/
219
235
public function jsonSerialize ()
220
236
{
0 commit comments