@@ -55,11 +55,11 @@ abstract class AbstractEnum
55
55
private static array $ instances = [];
56
56
57
57
/**
58
- * Constructor is private to ensure instances are created through static methods
58
+ * Constructor is private to ensure instances are created through static methods.
59
59
*
60
60
* @since n.e.x.t
61
- * @param string $value The enum value
62
- * @param string $name The constant name
61
+ * @param string $value The enum value.
62
+ * @param string $name The constant name.
63
63
*/
64
64
final private function __construct (string $ value , string $ name )
65
65
{
@@ -68,12 +68,12 @@ final private function __construct(string $value, string $name)
68
68
}
69
69
70
70
/**
71
- * Magic getter to provide read-only access to properties
71
+ * Provides read-only access to properties.
72
72
*
73
73
* @since n.e.x.t
74
- * @param string $property The property name
75
- * @return mixed
76
- * @throws BadMethodCallException If property doesn't exist
74
+ * @param string $property The property name.
75
+ * @return mixed The property value.
76
+ * @throws BadMethodCallException If property doesn't exist.
77
77
*/
78
78
final public function __get (string $ property )
79
79
{
@@ -87,12 +87,12 @@ final public function __get(string $property)
87
87
}
88
88
89
89
/**
90
- * Magic setter to prevent property modification
90
+ * Prevents property modification.
91
91
*
92
92
* @since n.e.x.t
93
- * @param string $property The property name
94
- * @param mixed $value The value to set
95
- * @throws BadMethodCallException Always, as enum properties are read-only
93
+ * @param string $property The property name.
94
+ * @param mixed $value The value to set.
95
+ * @throws BadMethodCallException Always, as enum properties are read-only.
96
96
*/
97
97
final public function __set (string $ property , $ value ): void
98
98
{
@@ -102,12 +102,12 @@ final public function __set(string $property, $value): void
102
102
}
103
103
104
104
/**
105
- * Create an enum instance from a value, throws exception if invalid
105
+ * Creates an enum instance from a value, throws exception if invalid.
106
106
*
107
107
* @since n.e.x.t
108
- * @param string $value The enum value
109
- * @return static
110
- * @throws InvalidArgumentException If the value is not valid
108
+ * @param string $value The enum value.
109
+ * @return static The enum instance.
110
+ * @throws InvalidArgumentException If the value is not valid.
111
111
*/
112
112
final public static function from (string $ value ): self
113
113
{
@@ -121,11 +121,11 @@ final public static function from(string $value): self
121
121
}
122
122
123
123
/**
124
- * Try to create an enum instance from a value, returns null if invalid
124
+ * Tries to create an enum instance from a value, returns null if invalid.
125
125
*
126
126
* @since n.e.x.t
127
- * @param string $value The enum value
128
- * @return static|null
127
+ * @param string $value The enum value.
128
+ * @return static|null The enum instance or null.
129
129
*/
130
130
final public static function tryFrom (string $ value ): ?self
131
131
{
@@ -139,10 +139,10 @@ final public static function tryFrom(string $value): ?self
139
139
}
140
140
141
141
/**
142
- * Get all enum cases
142
+ * Gets all enum cases.
143
143
*
144
144
* @since n.e.x.t
145
- * @return static[]
145
+ * @return static[] Array of all enum instances.
146
146
*/
147
147
final public static function cases (): array
148
148
{
@@ -155,11 +155,11 @@ final public static function cases(): array
155
155
}
156
156
157
157
/**
158
- * Check if this enum has the same value as the given value
158
+ * Checks if this enum has the same value as the given value.
159
159
*
160
160
* @since n.e.x.t
161
- * @param string|self $other The value or enum to compare
162
- * @return bool
161
+ * @param string|self $other The value or enum to compare.
162
+ * @return bool True if values are equal.
163
163
*/
164
164
final public function equals ($ other ): bool
165
165
{
@@ -171,47 +171,47 @@ final public function equals($other): bool
171
171
}
172
172
173
173
/**
174
- * Check if this enum is the same instance type and value as another enum
174
+ * Checks if this enum is the same instance type and value as another enum.
175
175
*
176
176
* @since n.e.x.t
177
- * @param self $other The other enum to compare
178
- * @return bool
177
+ * @param self $other The other enum to compare.
178
+ * @return bool True if enums are identical.
179
179
*/
180
180
final public function is (self $ other ): bool
181
181
{
182
182
return $ this === $ other ; // Since we're using singletons, we can use identity comparison
183
183
}
184
184
185
185
/**
186
- * Get all valid values for this enum
186
+ * Gets all valid values for this enum.
187
187
*
188
188
* @since n.e.x.t
189
- * @return array<string, string>
189
+ * @return array<string, string> Map of constant names to values.
190
190
*/
191
191
final public static function getValues (): array
192
192
{
193
193
return self ::getConstants ();
194
194
}
195
195
196
196
/**
197
- * Check if a value is valid for this enum
197
+ * Checks if a value is valid for this enum.
198
198
*
199
199
* @since n.e.x.t
200
- * @param string $value The value to check
201
- * @return bool
200
+ * @param string $value The value to check.
201
+ * @return bool True if value is valid.
202
202
*/
203
203
final public static function isValidValue (string $ value ): bool
204
204
{
205
205
return in_array ($ value , self ::getValues (), true );
206
206
}
207
207
208
208
/**
209
- * Get or create a singleton instance for the given value and name
209
+ * Gets or creates a singleton instance for the given value and name.
210
210
*
211
211
* @since n.e.x.t
212
- * @param string $value The enum value
213
- * @param string $name The constant name
214
- * @return static
212
+ * @param string $value The enum value.
213
+ * @param string $name The constant name.
214
+ * @return static The enum instance.
215
215
*/
216
216
private static function getInstance (string $ value , string $ name ): self
217
217
{
@@ -231,11 +231,11 @@ private static function getInstance(string $value, string $name): self
231
231
}
232
232
233
233
/**
234
- * Get all constants for this enum class
234
+ * Gets all constants for this enum class.
235
235
*
236
236
* @since n.e.x.t
237
- * @return array<string, string>
238
- * @throws \RuntimeException If invalid constant found
237
+ * @return array<string, string> Map of constant names to values.
238
+ * @throws \RuntimeException If invalid constant found.
239
239
*/
240
240
final protected static function getConstants (): array
241
241
{
@@ -282,13 +282,13 @@ final protected static function getConstants(): array
282
282
}
283
283
284
284
/**
285
- * Handle dynamic method calls for enum checking
285
+ * Handles dynamic method calls for enum checking.
286
286
*
287
287
* @since n.e.x.t
288
- * @param string $name The method name
289
- * @param array<mixed> $arguments The method arguments
290
- * @return bool
291
- * @throws BadMethodCallException If the method doesn't exist
288
+ * @param string $name The method name.
289
+ * @param array<mixed> $arguments The method arguments.
290
+ * @return bool True if the enum value matches.
291
+ * @throws BadMethodCallException If the method doesn't exist.
292
292
*/
293
293
final public function __call (string $ name , array $ arguments ): bool
294
294
{
@@ -308,13 +308,13 @@ final public function __call(string $name, array $arguments): bool
308
308
}
309
309
310
310
/**
311
- * Handle static method calls for enum creation
311
+ * Handles static method calls for enum creation.
312
312
*
313
313
* @since n.e.x.t
314
- * @param string $name The method name
315
- * @param array<mixed> $arguments The method arguments
316
- * @return static
317
- * @throws BadMethodCallException If the method doesn't exist
314
+ * @param string $name The method name.
315
+ * @param array<mixed> $arguments The method arguments.
316
+ * @return static The enum instance.
317
+ * @throws BadMethodCallException If the method doesn't exist.
318
318
*/
319
319
final public static function __callStatic (string $ name , array $ arguments ): self
320
320
{
@@ -331,11 +331,11 @@ final public static function __callStatic(string $name, array $arguments): self
331
331
}
332
332
333
333
/**
334
- * Convert camelCase to CONSTANT_CASE
334
+ * Converts camelCase to CONSTANT_CASE.
335
335
*
336
336
* @since n.e.x.t
337
- * @param string $camelCase The camelCase string
338
- * @return string The CONSTANT_CASE version
337
+ * @param string $camelCase The camelCase string.
338
+ * @return string The CONSTANT_CASE version.
339
339
*/
340
340
private static function camelCaseToConstant (string $ camelCase ): string
341
341
{
@@ -347,10 +347,10 @@ private static function camelCaseToConstant(string $camelCase): string
347
347
}
348
348
349
349
/**
350
- * String representation of the enum
350
+ * Returns string representation of the enum.
351
351
*
352
352
* @since n.e.x.t
353
- * @return string
353
+ * @return string The enum value.
354
354
*/
355
355
final public function __toString (): string
356
356
{
0 commit comments