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

DataType   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 11
c 0
b 0
f 0
dl 0
loc 26
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 DataType
10
 *
11
 * @package Level23\Druid\Types
12
 */
13
final class DataType 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 29
Loading history...
14
{
15
    public const STRING = 'string';
16
    public const FLOAT  = 'float';
17
    public const LONG   = 'long';
18
    public const DOUBLE = 'double';
19
20
    /**
21
     * Validate the DataType.
22
     *
23
     * @param string $outputType
24
     *
25
     * @return string
26
     * @throws InvalidArgumentException
27
     */
28 97
    public static function validate(string $outputType): string
29
    {
30 97
        $outputType = strtolower($outputType);
31 97
        if (!self::isValidValue($outputType)) {
32 3
            throw new InvalidArgumentException(
33 3
                'The given output type is invalid: ' . $outputType . '. ' .
34 3
                'Allowed are: ' . implode(',', DataType::values())
35
            );
36
        }
37
38 94
        return $outputType;
39
    }
40
}