Passed
Pull Request — master (#38)
by Teye
07:11
created

FlattenFieldType   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 10
c 1
b 0
f 0
dl 0
loc 37
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 11 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Types;
5
6
use InvalidArgumentException;
7
8
/**
9
 * Class FlattenFieldType
10
 *
11
 * @package Level23\Druid\Types
12
 */
13
final class FlattenFieldType extends Enum
14
{
15
    /**
16
     * root, referring to a field at the root level of the record. Only really useful if useFieldDiscovery is false.
17
     */
18
    public const ROOT = 'root';
19
    /**
20
     * referring to a field using JsonPath notation. Supported by most data formats that offer nesting, including avro,
21
     * json, orc, and parquet.
22
     *
23
     * @see https://github.com/json-path/JsonPath
24
     */
25
    public const PATH = 'path';
26
    /**
27
     * referring to a field using jackson-jq notation. Only supported for the json format
28
     *
29
     * @see https://github.com/eiiches/jackson-jq
30
     */
31
    public const JQ = 'jq';
32
33
    /**
34
     * @param string $flattenFieldType
35
     *
36
     * @return string
37
     * @throws InvalidArgumentException
38
     */
39 14
    public static function validate(string $flattenFieldType): string
40
    {
41 14
        $flattenFieldType = strtolower($flattenFieldType);
42 14
        if (!FlattenFieldType::isValidValue($flattenFieldType)) {
43 1
            throw new InvalidArgumentException(
44 1
                'The given flatten field type is invalid: ' . $flattenFieldType . '. ' .
45 1
                'Allowed are: ' . implode(', ', FlattenFieldType::values())
46
            );
47
        }
48
49 13
        return $flattenFieldType;
50
    }
51
}