Passed
Pull Request — master (#38)
by Teye
05:43
created

ArithmeticFunction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 12
c 1
b 0
f 0
dl 0
loc 25
ccs 7
cts 7
cp 1
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Types;
5
6
use InvalidArgumentException;
7
8
/**
9
 * Class ArithmeticFunction
10
 *
11
 * @package Level23\Druid\Types
12
 */
13
final class ArithmeticFunction extends Enum
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_ENUM, expecting T_STRING or T_NAME_QUALIFIED or T_NAME_FULLY_QUALIFIED or T_NAME_RELATIVE on line 13 at column 39
Loading history...
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
}