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