Total Complexity | 4 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
5 | class Role |
||
6 | { |
||
7 | /** |
||
8 | * @var string |
||
9 | */ |
||
10 | private $value; |
||
11 | |||
12 | /** |
||
13 | * @var string[] |
||
14 | */ |
||
15 | private $allowedValues = [ |
||
16 | 'admin', |
||
17 | 'vsv', |
||
18 | 'contact', |
||
19 | ]; |
||
20 | |||
21 | /** |
||
22 | * @param string $value |
||
23 | */ |
||
24 | public function __construct(string $value) |
||
25 | { |
||
26 | if (!in_array($value, $this->allowedValues)) { |
||
27 | throw new \InvalidArgumentException('Invalid value: '.$value.' for role.'); |
||
28 | } |
||
29 | $this->value = $value; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @return string |
||
34 | */ |
||
35 | public function toNative(): string |
||
36 | { |
||
37 | return $this->value; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param Role $role |
||
42 | * @return bool |
||
43 | */ |
||
44 | public function equals(Role $role): bool |
||
47 | } |
||
48 | } |
||
49 |