Skip to content

Commit 90f9b0c

Browse files
committed
[Int|String]BackedEnum -> Emulated[Int|String]Enum
1 parent 5c76705 commit 90f9b0c

13 files changed

+38
-38
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ if (PHP_VERSION_ID < 80100) {
2424

2525
namespace Vendor;
2626

27-
use Mabe\Enum\Cl\IntBackedEnum;
27+
use Mabe\Enum\Cl\EmulatedIntEnum;
2828

29-
final class MyEnum extends IntBackedEnum
29+
final class MyEnum extends EmulatedIntEnum
3030
{
3131
const ZERO = 0;
3232
const ONE = 1;

examples/doctrine/src/UserStatus-polyfill.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace Example;
44

5-
use Mabe\Enum\Cl\StringBackedEnum;
5+
use Mabe\Enum\Cl\EmulatedStringEnum;
66

77
/**
88
* @method static UserStatus ACTIVE()
99
* @method static UserStatus BANNED()
1010
* @method static UserStatus DELETED()
1111
*/
12-
final class UserStatus extends StringBackedEnum
12+
final class UserStatus extends EmulatedStringEnum
1313
{
1414
/** @internal */
1515
const ACTIVE = 'active';

src/Mabe/Enum/Cl/EmulatedBackedEnum.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ final public static function from($value): BackedEnum
129129

130130
$name = \array_search($value, self::$caseConstants[static::class], true);
131131
if ($name === false) {
132-
if (\is_subclass_of(static::class, IntBackedEnum::class)) {
132+
if (\is_subclass_of(static::class, EmulatedIntEnum::class)) {
133133
if (!\is_int($value)) {
134134
throw new TypeError(static::class . '::from(): Argument #1 ($value) must be of type int, ' . \get_debug_type($value) . ' given');
135135
}
136136

137137
throw new ValueError("{$value} is not a valid backing value for enum \"" . static::class . '"');
138-
} elseif (\is_subclass_of(static::class, StringBackedEnum::class)) {
138+
} elseif (\is_subclass_of(static::class, EmulatedStringEnum::class)) {
139139
if (!\is_string($value)) {
140140
throw new TypeError(static::class . '::from(): Argument #1 ($value) must be of type string, ' . \get_debug_type($value) . ' given');
141141
}
@@ -214,8 +214,8 @@ private static function init(string $enumClass)
214214
$cases = [];
215215
foreach ($caseConstants as $name => $value) {
216216
assert(
217-
(\is_subclass_of($enumClass, IntBackedEnum::class) && \is_int($value))
218-
|| (\is_subclass_of($enumClass, StringBackedEnum::class) && \is_string($value)),
217+
(\is_subclass_of($enumClass, EmulatedIntEnum::class) && \is_int($value))
218+
|| (\is_subclass_of($enumClass, EmulatedStringEnum::class) && \is_string($value)),
219219
"Enum case constant \"{$enumClass}::{$name}\" does not match enum backing type"
220220
);
221221

src/Mabe/Enum/Cl/IntBackedEnum.php renamed to src/Mabe/Enum/Cl/EmulatedIntEnum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @psalm-immutable
1313
*/
14-
abstract class IntBackedEnum extends EmulatedBackedEnum
14+
abstract class EmulatedIntEnum extends EmulatedBackedEnum
1515
{
1616
/**
1717
* The value of the current case

src/Mabe/Enum/Cl/StringBackedEnum.php renamed to src/Mabe/Enum/Cl/EmulatedStringEnum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @psalm-immutable
1313
*/
14-
abstract class StringBackedEnum extends EmulatedBackedEnum
14+
abstract class EmulatedStringEnum extends EmulatedBackedEnum
1515
{
1616
/**
1717
* The value of the current case

tests/AmbiguousBackingValuesEnumEmulated.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php declare(strict_types=1);
22

3-
final class AmbiguousStringValuesEnumEmulated extends Mabe\Enum\Cl\StringBackedEnum
3+
final class AmbiguousStringValuesEnumEmulated extends Mabe\Enum\Cl\EmulatedStringEnum
44
{
55
const TEST1 = 'test';
66
const TEST2 = 'test';
77
}
88

9-
final class AmbiguousIntValuesEnumEmulated extends Mabe\Enum\Cl\IntBackedEnum
9+
final class AmbiguousIntValuesEnumEmulated extends Mabe\Enum\Cl\EmulatedIntEnum
1010
{
1111
const TEST1 = 1;
1212
const TEST2 = 1;

tests/BasicIntEnum-emulated.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @method static self EIGHT()
1313
* @method static self NINE()
1414
*/
15-
final class BasicIntEnum extends Mabe\Enum\Cl\IntBackedEnum
15+
final class BasicIntEnum extends Mabe\Enum\Cl\EmulatedIntEnum
1616
{
1717
/** @internal */
1818
const ZERO = 0;

tests/BasicStringEnum-emulated.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
final class BasicStringEnum extends Mabe\Enum\Cl\StringBackedEnum
3+
final class BasicStringEnum extends Mabe\Enum\Cl\EmulatedStringEnum
44
{
55
const ZERO = '0';
66
const ONE = '1';

tests/EnumExistsTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function testUnitEnumNative()
1515
static::assertTrue(enum_exists(__FUNCTION__));
1616
}
1717

18-
public function testUnitEnumEmulated()
18+
public function testEmulatedUnitEnum()
1919
{
2020
if (PHP_VERSION_ID >= 80100) {
2121
$this->markTestSkipped('This test is for PHP < 8.1 only');
@@ -25,23 +25,23 @@ public function testUnitEnumEmulated()
2525
static::assertTrue(enum_exists(__FUNCTION__));
2626
}
2727

28-
public function testIntBackedEnumEmulated()
28+
public function testEmulatedIntEnum()
2929
{
3030
if (PHP_VERSION_ID >= 80100) {
3131
$this->markTestSkipped('This test is for PHP < 8.1 only');
3232
}
3333

34-
eval('final class ' . __FUNCTION__ . ' extends Mabe\Enum\Cl\IntBackedEnum {}');
34+
eval('final class ' . __FUNCTION__ . ' extends Mabe\Enum\Cl\EmulatedIntEnum {}');
3535
static::assertTrue(enum_exists(__FUNCTION__));
3636
}
3737

38-
public function testStringBackedEnumEmulated()
38+
public function testEmulatedStringEnum()
3939
{
4040
if (PHP_VERSION_ID >= 80100) {
4141
$this->markTestSkipped('This test is for PHP < 8.1 only');
4242
}
4343

44-
eval('final class ' . __FUNCTION__ . ' extends Mabe\Enum\Cl\StringBackedEnum {}');
44+
eval('final class ' . __FUNCTION__ . ' extends Mabe\Enum\Cl\EmulatedStringEnum {}');
4545
static::assertTrue(enum_exists(__FUNCTION__));
4646
}
4747

@@ -102,7 +102,7 @@ public function testAutoloadTrue()
102102
$classLoader = function (string $class) use ($enumClass, &$called) {
103103
if ($class === $enumClass) {
104104
$called++;
105-
eval('final class ' . $class . ' extends Mabe\Enum\Cl\StringBackedEnum {}');
105+
eval('final class ' . $class . ' extends Mabe\Enum\Cl\EmulatedStringEnum {}');
106106
}
107107
};
108108

tests/InvalidBackingTypeEnumEmulated.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)