JsonInputFormat   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
c 1
b 0
f 0
dl 0
loc 44
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 13 3
A __construct() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\InputFormats;
5
6
class JsonInputFormat implements InputFormatInterface
7
{
8
    /**
9
     * @var \Level23\Druid\InputFormats\FlattenSpec|null
10
     */
11
    protected ?FlattenSpec $flattenSpec;
12
13
    /**
14
     * @var array<string,bool>
15
     */
16
    protected ?array $features;
17
18
    /**
19
     * @param FlattenSpec|null        $flattenSpec  Specifies flattening configuration for nested JSON data. See
20
     *                                              flattenSpec for more info.
21
     * @param array<string,bool>|null $features     JSON parser features supported by Jackson library. Those features
22
     *                                              will be applied when parsing the input JSON data.
23
     *
24
     * @see https://github.com/FasterXML/jackson-core/wiki/JsonParser-Features
25
     */
26 3
    public function __construct(?FlattenSpec $flattenSpec = null, ?array $features = null)
27
    {
28 3
        $this->flattenSpec = $flattenSpec;
29 3
        $this->features    = $features;
30
    }
31
32
    /**
33
     * Return the JsonInputFormat so that it can be used in a druid query.
34
     *
35
     * @return array<string,string|array<string,bool>|array<string,bool|array<array<string,string>>>>
36
     */
37 1
    public function toArray(): array
38
    {
39 1
        $result = ['type' => 'json'];
40
41 1
        if (!empty($this->flattenSpec)) {
42 1
            $result['flattenSpec'] = $this->flattenSpec->toArray();
43
        }
44
45 1
        if (!empty($this->features)) {
46 1
            $result['featureSpec'] = $this->features;
47
        }
48
49 1
        return $result;
50
    }
51
}