-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathStateEnum.php
More file actions
44 lines (36 loc) · 1.02 KB
/
StateEnum.php
File metadata and controls
44 lines (36 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
declare(strict_types=1);
namespace Yokai\EnumBundle\Tests\Unit\Fixtures;
use Yokai\EnumBundle\EnumInterface;
use Yokai\EnumBundle\Exception\InvalidArgumentException;
/**
* Direct interface implementation.
* Values are hardcoded in `getChoices` method.
* Each value label is hardcoded in `getChoices` method.
*
* @author Yann Eugoné <eugone.yann@gmail.com>
*/
class StateEnum implements EnumInterface
{
public function getName(): string
{
return __CLASS__;
}
public function getValues(): array
{
return \array_values($this->getChoices());
}
public function getChoices(): array
{
return ['New' => 'new', 'Validated' => 'validated', 'Disabled' => 'disabled'];
}
public function getLabel(mixed $value): string
{
$choices = $this->getChoices();
$label = \array_search($value, $choices, true);
if ($label === false) {
throw InvalidArgumentException::enumMissingValue($this, $value);
}
return $label;
}
}