Skip to content

Commit 5ed0255

Browse files
committed
Add support for direct value comparisons
1 parent a4c5c09 commit 5ed0255

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/IsBackedEnum.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
/**
77
* @implements \Webfox\LaravelBackedEnums\BackedEnum<string,string>
8+
* @mixin \BackedEnum<string,string>
89
*/
910
trait IsBackedEnum
1011
{
1112

12-
1313
protected static function ensureImplementsInterface(): void
1414
{
1515
throw_unless(class_implements(static::class, BackedEnum::class), new \Exception(sprintf('Enum %s must implement BackedEnum', static::class)));
@@ -100,7 +100,7 @@ public function toJson($options = 0): array
100100
public function isA($value): bool
101101
{
102102
static::ensureImplementsInterface();
103-
return $this == $value;
103+
return $this->isAny([$value]);
104104
}
105105

106106
public function isAn(string $value): bool
@@ -118,6 +118,12 @@ public function isNot(string $value): bool
118118
public function isAny(array $values): bool
119119
{
120120
static::ensureImplementsInterface();
121+
122+
if (empty($values)) {
123+
return false;
124+
}
125+
126+
$values = array_map(fn($value) => $value instanceof static ? $value : static::from($value), $values);
121127
return in_array($this, $values);
122128
}
123129

0 commit comments

Comments
 (0)