Skip to content

Commit 9253f01

Browse files
Handle BackedEnum keys in addState method of EntityState
1 parent 49a26e9 commit 9253f01

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/EntityList/Commands/EntityState.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Code16\Sharp\EntityList\Commands;
44

5+
use BackedEnum;
56
use Code16\Sharp\Exceptions\EntityList\SharpInvalidEntityStateException;
67
use Code16\Sharp\Exceptions\SharpInvalidConfigException;
8+
use InvalidArgumentException;
79

810
/**
911
* Base class for applicative Entity States.
@@ -19,8 +21,12 @@ public function states(): array
1921
return $this->states;
2022
}
2123

22-
protected function addState(string $key, string $label, ?string $color = null): self
24+
protected function addState($key, string $label, ?string $color = null): self
2325
{
26+
if ($key instanceof BackedEnum && ! is_string($key = $key->value)) {
27+
throw new InvalidArgumentException('When using enum as a key, it must be string backed.');
28+
}
29+
2430
$this->states[$key] = [$label, $color];
2531

2632
return $this;

0 commit comments

Comments
 (0)