21
21
*
22
22
* @psalm-immutable
23
23
*/
24
- abstract class BackedEnumPolyfill implements BackedEnum
24
+ abstract class EmulatedBackedEnum implements BackedEnum
25
25
{
26
26
/**
27
27
* The name of the current case
@@ -42,14 +42,14 @@ abstract class BackedEnumPolyfill implements BackedEnum
42
42
/**
43
43
* A map of case names and values by enumeration class
44
44
*
45
- * @var array<class-string<BackedEnumPolyfill >, array<string, int|string>>
45
+ * @var array<class-string<EmulatedBackedEnum >, array<string, int|string>>
46
46
*/
47
47
private static $ caseConstants = [];
48
48
49
49
/**
50
50
* A map of case names and instances by enumeration class
51
51
*
52
- * @var array<class-string<BackedEnumPolyfill >, array<string, BackedEnumPolyfill >>
52
+ * @var array<class-string<EmulatedBackedEnum >, array<string, EmulatedBackedEnum >>
53
53
*/
54
54
private static $ cases = [];
55
55
@@ -129,13 +129,13 @@ final public static function from($value): BackedEnum
129
129
130
130
$ name = \array_search ($ value , self ::$ caseConstants [static ::class], true );
131
131
if ($ name === false ) {
132
- if (\is_subclass_of (static ::class, IntEnumPolyfill ::class)) {
132
+ if (\is_subclass_of (static ::class, IntBackedEnum ::class)) {
133
133
if (!\is_int ($ value )) {
134
134
throw new TypeError (static ::class . '::from(): Argument #1 ($value) must be of type int, ' . \get_debug_type ($ value ) . ' given ' );
135
135
}
136
136
137
137
throw new ValueError ("{$ value } is not a valid backing value for enum \"" . static ::class . '" ' );
138
- } elseif (\is_subclass_of (static ::class, StringEnumPolyfill ::class)) {
138
+ } elseif (\is_subclass_of (static ::class, StringBackedEnum ::class)) {
139
139
if (!\is_string ($ value )) {
140
140
throw new TypeError (static ::class . '::from(): Argument #1 ($value) must be of type string, ' . \get_debug_type ($ value ) . ' given ' );
141
141
}
@@ -214,8 +214,8 @@ private static function init(string $enumClass)
214
214
$ cases = [];
215
215
foreach ($ caseConstants as $ name => $ value ) {
216
216
assert (
217
- (\is_subclass_of ($ enumClass , IntEnumPolyfill ::class) && \is_int ($ value ))
218
- || (\is_subclass_of ($ enumClass , StringEnumPolyfill ::class) && \is_string ($ value )),
217
+ (\is_subclass_of ($ enumClass , IntBackedEnum ::class) && \is_int ($ value ))
218
+ || (\is_subclass_of ($ enumClass , StringBackedEnum ::class) && \is_string ($ value )),
219
219
"Enum case constant \"{$ enumClass }:: {$ name }\" does not match enum backing type "
220
220
);
221
221
0 commit comments