1414 * @author Matthieu Napoli <matthieu@mnapoli.fr>
1515 * @author Daniel Costa <danielcosta@gmail.com>
1616 * @author Mirosław Filip <mirfilip@gmail.com>
17+ *
18+ * @template T
19+ * @psalm-immutable
1720 */
1821abstract class Enum implements \JsonSerializable
1922{
2023 /**
2124 * Enum value
2225 *
2326 * @var mixed
27+ * @psalm-var T
2428 */
2529 protected $ value ;
2630
2731 /**
2832 * Store existing constants in a static cache per object.
2933 *
3034 * @var array
35+ * @psalm-var array<class-string, array<string, mixed>>
3136 */
3237 protected static $ cache = [];
3338
@@ -36,6 +41,8 @@ abstract class Enum implements \JsonSerializable
3641 *
3742 * @param mixed $value
3843 *
44+ * @psalm-param T $value
45+ * @psalm-suppress InvalidCast
3946 * @throws \UnexpectedValueException if incompatible type is given.
4047 */
4148 public function __construct ($ value )
@@ -53,6 +60,7 @@ public function __construct($value)
5360
5461 /**
5562 * @return mixed
63+ * @psalm-return T
5664 */
5765 public function getValue ()
5866 {
@@ -62,6 +70,7 @@ public function getValue()
6270 /**
6371 * Returns the enum key (i.e. the constant name).
6472 *
73+ * @psalm-pure
6574 * @return mixed
6675 */
6776 public function getKey ()
@@ -70,6 +79,7 @@ public function getKey()
7079 }
7180
7281 /**
82+ * @psalm-suppress InvalidCast
7383 * @return string
7484 */
7585 public function __toString ()
@@ -83,6 +93,7 @@ public function __toString()
8393 *
8494 * This method is final, for more information read https://github.com/myclabs/php-enum/issues/4
8595 *
96+ * @psalm-param mixed $variable
8697 * @return bool
8798 */
8899 final public function equals ($ variable = null ): bool
@@ -121,6 +132,8 @@ public static function values()
121132 /**
122133 * Returns all possible values as an array
123134 *
135+ * @psalm-pure
136+ * @psalm-return array<string, mixed>
124137 * @return array Constant name in key, constant value in value
125138 */
126139 public static function toArray ()
@@ -138,6 +151,7 @@ public static function toArray()
138151 * Check if is valid enum value
139152 *
140153 * @param $value
154+ * @psalm-param mixed $value
141155 *
142156 * @return bool
143157 */
@@ -150,6 +164,7 @@ public static function isValid($value)
150164 * Check if is valid enum key
151165 *
152166 * @param $key
167+ * @psalm-param string $key
153168 *
154169 * @return bool
155170 */
@@ -165,6 +180,8 @@ public static function isValidKey($key)
165180 *
166181 * @param $value
167182 *
183+ * @psalm-param mixed $value
184+ * @psalm-pure
168185 * @return mixed
169186 */
170187 public static function search ($ value )
0 commit comments