@@ -58,7 +58,7 @@ abstract class AbstractEnum
58
58
* @param string|int $value The enum value
59
59
* @param string $name The constant name
60
60
*/
61
- private function __construct ($ value , string $ name )
61
+ final private function __construct ($ value , string $ name )
62
62
{
63
63
$ this ->value = $ value ;
64
64
$ this ->name = $ name ;
@@ -71,7 +71,7 @@ private function __construct($value, string $name)
71
71
* @return mixed
72
72
* @throws BadMethodCallException If property doesn't exist
73
73
*/
74
- public function __get (string $ property )
74
+ final public function __get (string $ property )
75
75
{
76
76
if ($ property === 'value ' || $ property === 'name ' ) {
77
77
return $ this ->$ property ;
@@ -89,7 +89,7 @@ public function __get(string $property)
89
89
* @param mixed $value The value to set
90
90
* @throws BadMethodCallException Always, as enum properties are read-only
91
91
*/
92
- public function __set (string $ property , $ value ): void
92
+ final public function __set (string $ property , $ value ): void
93
93
{
94
94
throw new BadMethodCallException (
95
95
sprintf ('Cannot modify property %s::%s - enum properties are read-only ' , static ::class, $ property )
@@ -103,7 +103,7 @@ public function __set(string $property, $value): void
103
103
* @return static
104
104
* @throws InvalidArgumentException If the value is not valid
105
105
*/
106
- public static function from ($ value ): self
106
+ final public static function from ($ value ): self
107
107
{
108
108
$ instance = self ::tryFrom ($ value );
109
109
if ($ instance === null ) {
@@ -120,7 +120,7 @@ public static function from($value): self
120
120
* @param string|int $value The enum value
121
121
* @return static|null
122
122
*/
123
- public static function tryFrom ($ value ): ?self
123
+ final public static function tryFrom ($ value ): ?self
124
124
{
125
125
$ constants = self ::getConstants ();
126
126
foreach ($ constants as $ name => $ constantValue ) {
@@ -136,7 +136,7 @@ public static function tryFrom($value): ?self
136
136
*
137
137
* @return static[]
138
138
*/
139
- public static function cases (): array
139
+ final public static function cases (): array
140
140
{
141
141
$ cases = [];
142
142
$ constants = self ::getConstants ();
@@ -152,7 +152,7 @@ public static function cases(): array
152
152
* @param string|int|self $other The value or enum to compare
153
153
* @return bool
154
154
*/
155
- public function equals ($ other ): bool
155
+ final public function equals ($ other ): bool
156
156
{
157
157
if ($ other instanceof self) {
158
158
return $ this ->is ($ other );
@@ -167,7 +167,7 @@ public function equals($other): bool
167
167
* @param self $other The other enum to compare
168
168
* @return bool
169
169
*/
170
- public function is (self $ other ): bool
170
+ final public function is (self $ other ): bool
171
171
{
172
172
return $ this === $ other ; // Since we're using singletons, we can use identity comparison
173
173
}
@@ -177,7 +177,7 @@ public function is(self $other): bool
177
177
*
178
178
* @return array<string, string|int>
179
179
*/
180
- public static function getValues (): array
180
+ final public static function getValues (): array
181
181
{
182
182
return self ::getConstants ();
183
183
}
@@ -188,31 +188,17 @@ public static function getValues(): array
188
188
* @param string|int $value The value to check
189
189
* @return bool
190
190
*/
191
- public static function isValidValue ($ value ): bool
191
+ final public static function isValidValue ($ value ): bool
192
192
{
193
193
return in_array ($ value , self ::getValues (), true );
194
194
}
195
195
196
- /**
197
- * Create an enum instance from a value (deprecated, use from() instead)
198
- *
199
- * @param string|int $value The enum value
200
- * @return static
201
- * @throws InvalidArgumentException If the value is not valid
202
- * @deprecated Use from() method instead
203
- */
204
- public static function fromValue ($ value ): self
205
- {
206
- return self ::from ($ value );
207
- }
208
-
209
196
/**
210
197
* Get or create a singleton instance for the given value and name
211
198
*
212
199
* @param string|int $value The enum value
213
200
* @param string $name The constant name
214
201
* @return static
215
- * @phpstan-return static
216
202
*/
217
203
private static function getInstance ($ value , string $ name ): self
218
204
{
@@ -237,7 +223,7 @@ private static function getInstance($value, string $name): self
237
223
* @return array<string, string|int>
238
224
* @throws \RuntimeException If invalid constant found
239
225
*/
240
- protected static function getConstants (): array
226
+ final protected static function getConstants (): array
241
227
{
242
228
$ className = static ::class;
243
229
@@ -289,7 +275,7 @@ protected static function getConstants(): array
289
275
* @return bool
290
276
* @throws BadMethodCallException If the method doesn't exist
291
277
*/
292
- public function __call (string $ name , array $ arguments )
278
+ final public function __call (string $ name , array $ arguments ): bool
293
279
{
294
280
// Handle is* methods
295
281
if (strpos ($ name , 'is ' ) === 0 ) {
@@ -314,7 +300,7 @@ public function __call(string $name, array $arguments)
314
300
* @return static
315
301
* @throws BadMethodCallException If the method doesn't exist
316
302
*/
317
- public static function __callStatic (string $ name , array $ arguments )
303
+ final public static function __callStatic (string $ name , array $ arguments ): self
318
304
{
319
305
$ constantName = self ::camelCaseToConstant ($ name );
320
306
$ constants = self ::getConstants ();
@@ -348,7 +334,7 @@ private static function camelCaseToConstant(string $camelCase): string
348
334
*
349
335
* @return string
350
336
*/
351
- public function __toString (): string
337
+ final public function __toString (): string
352
338
{
353
339
return (string ) $ this ->value ;
354
340
}
0 commit comments