@@ -31,6 +31,7 @@ abstract class Enum implements \JsonSerializable
3131 /**
3232 * Store existing constants in a static cache per object.
3333 *
34+ *
3435 * @var array
3536 * @psalm-var array<class-string, array<string, mixed>>
3637 */
@@ -39,26 +40,30 @@ abstract class Enum implements \JsonSerializable
3940 /**
4041 * Creates a new value of some type
4142 *
43+ * @psalm-pure
4244 * @param mixed $value
4345 *
44- * @psalm-param T $value
45- * @psalm-suppress InvalidCast
46+ * @psalm-param static<T>|T $value
4647 * @throws \UnexpectedValueException if incompatible type is given.
4748 */
4849 public function __construct ($ value )
4950 {
5051 if ($ value instanceof static) {
52+ /** @psalm-var T */
5153 $ value = $ value ->getValue ();
5254 }
5355
5456 if (!$ this ->isValid ($ value )) {
57+ /** @psalm-suppress InvalidCast */
5558 throw new \UnexpectedValueException ("Value ' $ value' is not part of the enum " . static ::class);
5659 }
5760
61+ /** @psalm-var T */
5862 $ this ->value = $ value ;
5963 }
6064
6165 /**
66+ * @psalm-pure
6267 * @return mixed
6368 * @psalm-return T
6469 */
@@ -79,6 +84,7 @@ public function getKey()
7984 }
8085
8186 /**
87+ * @psalm-pure
8288 * @psalm-suppress InvalidCast
8389 * @return string
8490 */
@@ -93,6 +99,7 @@ public function __toString()
9399 *
94100 * This method is final, for more information read https://github.com/myclabs/php-enum/issues/4
95101 *
102+ * @psalm-pure
96103 * @psalm-param mixed $variable
97104 * @return bool
98105 */
@@ -106,6 +113,8 @@ final public function equals($variable = null): bool
106113 /**
107114 * Returns the names (keys) of all constants in the Enum class
108115 *
116+ * @psalm-pure
117+ * @psalm-return list<string>
109118 * @return array
110119 */
111120 public static function keys ()
@@ -116,12 +125,15 @@ public static function keys()
116125 /**
117126 * Returns instances of the Enum class of all Enum constants
118127 *
128+ * @psalm-pure
129+ * @psalm-return array<string, static>
119130 * @return static[] Constant name in key, Enum instance in value
120131 */
121132 public static function values ()
122133 {
123134 $ values = array ();
124135
136+ /** @psalm-var T $value */
125137 foreach (static ::toArray () as $ key => $ value ) {
126138 $ values [$ key ] = new static ($ value );
127139 }
@@ -133,6 +145,8 @@ public static function values()
133145 * Returns all possible values as an array
134146 *
135147 * @psalm-pure
148+ * @psalm-suppress ImpureStaticProperty
149+ *
136150 * @psalm-return array<string, mixed>
137151 * @return array Constant name in key, constant value in value
138152 */
@@ -153,7 +167,7 @@ public static function toArray()
153167 *
154168 * @param $value
155169 * @psalm-param mixed $value
156- *
170+ * @psalm-pure
157171 * @return bool
158172 */
159173 public static function isValid ($ value )
@@ -166,7 +180,7 @@ public static function isValid($value)
166180 *
167181 * @param $key
168182 * @psalm-param string $key
169- *
183+ * @psalm-pure
170184 * @return bool
171185 */
172186 public static function isValidKey ($ key )
@@ -197,6 +211,7 @@ public static function search($value)
197211 * @param array $arguments
198212 *
199213 * @return static
214+ * @psalm-pure
200215 * @throws \BadMethodCallException
201216 */
202217 public static function __callStatic ($ name , $ arguments )
@@ -215,6 +230,7 @@ public static function __callStatic($name, $arguments)
215230 *
216231 * @return mixed
217232 * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
233+ * @psalm-pure
218234 */
219235 public function jsonSerialize ()
220236 {
0 commit comments