| Conditions | 3 |
| Paths | 3 |
| Total Lines | 17 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 3 |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 29 | 5 | private function validate(string $value): void |
|
| 30 | { |
||
| 31 | 5 | $constants = $this->getConstants(); |
|
| 32 | 5 | $valid = in_array($value, $constants, true); |
|
| 33 | 5 | if (!$valid) { |
|
| 34 | 2 | $class = get_class($this); |
|
| 35 | 2 | if (!empty($constants)) { |
|
| 36 | 1 | $implodedConstants = implode(PHP_EOL, $constants); |
|
| 37 | $message = <<< EOD |
||
| 38 | 1 | Invalid ENUM option for class {$class}. |
|
| 39 | 1 | Given: {$value}. Expected one of: |
|
| 40 | 1 | $implodedConstants |
|
| 41 | EOD; |
||
| 42 | } else { |
||
| 43 | 1 | $message = "Invalid ENUM: missing options. Class: {$class}."; |
|
| 44 | } |
||
| 45 | 2 | throw new EnumException($message); |
|
| 46 | } |
||
| 76 |