| Total Complexity | 2 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | final class ArithmeticFunction extends Enum |
||
|
|
|||
| 14 | { |
||
| 15 | public const ADD = '+'; |
||
| 16 | public const DIVIDE = '/'; |
||
| 17 | public const MULTIPLY = '*'; |
||
| 18 | public const SUBTRACT = '-'; |
||
| 19 | public const QUOTIENT = 'quotient'; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param string $function |
||
| 23 | * |
||
| 24 | * @return string |
||
| 25 | * @throws InvalidArgumentException |
||
| 26 | */ |
||
| 27 | 10 | public static function validate(string $function): string |
|
| 28 | { |
||
| 29 | 10 | $function = strtolower($function); |
|
| 30 | 10 | if (!ArithmeticFunction::isValidValue($function)) { |
|
| 31 | 1 | throw new InvalidArgumentException( |
|
| 32 | 1 | 'Invalid arithmetic function given: ' . $function . |
|
| 33 | 1 | '. Valid options are: ' . implode(',', ArithmeticFunction::values()) |
|
| 34 | ); |
||
| 35 | } |
||
| 36 | |||
| 37 | 9 | return $function; |
|
| 38 | } |
||
| 39 | } |