Skip to content

Commit f24ac13

Browse files
committed
Mark all methods as pure
This means every function can be called from an immutable / pure context Note: ToArray will fail psalm on this commit as (rightfully) there is an impure psalm issue
1 parent 27aa6b1 commit f24ac13

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/Enum.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ abstract class Enum implements \JsonSerializable
3131
/**
3232
* Store existing constants in a static cache per object.
3333
*
34+
* @psalm-pure
35+
*
3436
* @var array
3537
* @psalm-var array<class-string, array<string, mixed>>
3638
*/
@@ -39,6 +41,7 @@ abstract class Enum implements \JsonSerializable
3941
/**
4042
* Creates a new value of some type
4143
*
44+
* @psalm-pure
4245
* @param mixed $value
4346
*
4447
* @psalm-param static<T>|T $value
@@ -61,6 +64,7 @@ public function __construct($value)
6164
}
6265

6366
/**
67+
* @psalm-pure
6468
* @return mixed
6569
* @psalm-return T
6670
*/
@@ -72,7 +76,7 @@ public function getValue()
7276
/**
7377
* Returns the enum key (i.e. the constant name).
7478
*
75-
* @psalm-external-mutation-free
79+
* @psalm-pure
7680
* @return mixed
7781
*/
7882
public function getKey()
@@ -81,7 +85,7 @@ public function getKey()
8185
}
8286

8387
/**
84-
* @psalm-suppress InvalidCast
88+
* @psalm-pure
8589
* @return string
8690
*/
8791
public function __toString()
@@ -95,6 +99,7 @@ public function __toString()
9599
*
96100
* This method is final, for more information read https://github.com/myclabs/php-enum/issues/4
97101
*
102+
* @psalm-pure
98103
* @psalm-param mixed $variable
99104
* @return bool
100105
*/
@@ -108,7 +113,7 @@ final public function equals($variable = null): bool
108113
/**
109114
* Returns the names (keys) of all constants in the Enum class
110115
*
111-
* @psalm-external-mutation-free
116+
* @psalm-pure
112117
* @psalm-return list<string>
113118
* @return array
114119
*/
@@ -120,7 +125,7 @@ public static function keys()
120125
/**
121126
* Returns instances of the Enum class of all Enum constants
122127
*
123-
* @psalm-external-mutation-free
128+
* @psalm-pure
124129
* @psalm-return array<string, static>
125130
* @return static[] Constant name in key, Enum instance in value
126131
*/
@@ -139,7 +144,9 @@ public static function values()
139144
/**
140145
* Returns all possible values as an array
141146
*
142-
* @psalm-external-mutation-free
147+
* @psalm-pure
148+
* @psalm-suppress ImpureStaticProperty
149+
*
143150
* @psalm-return array<string, mixed>
144151
* @return array Constant name in key, constant value in value
145152
*/
@@ -160,7 +167,7 @@ public static function toArray()
160167
*
161168
* @param $value
162169
* @psalm-param mixed $value
163-
* @psalm-external-mutation-free
170+
* @psalm-pure
164171
* @return bool
165172
*/
166173
public static function isValid($value)
@@ -173,7 +180,7 @@ public static function isValid($value)
173180
*
174181
* @param $key
175182
* @psalm-param string $key
176-
* @psalm-external-mutation-free
183+
* @psalm-pure
177184
* @return bool
178185
*/
179186
public static function isValidKey($key)
@@ -189,7 +196,7 @@ public static function isValidKey($key)
189196
* @param $value
190197
*
191198
* @psalm-param mixed $value
192-
* @psalm-external-mutation-free
199+
* @psalm-pure
193200
* @return mixed
194201
*/
195202
public static function search($value)
@@ -204,7 +211,7 @@ public static function search($value)
204211
* @param array $arguments
205212
*
206213
* @return static
207-
* @psalm-external-mutation-free
214+
* @psalm-pure
208215
* @throws \BadMethodCallException
209216
*/
210217
public static function __callStatic($name, $arguments)
@@ -223,6 +230,7 @@ public static function __callStatic($name, $arguments)
223230
*
224231
* @return mixed
225232
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
233+
* @psalm-pure
226234
*/
227235
public function jsonSerialize()
228236
{

0 commit comments

Comments
 (0)