UniformGranularity   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
dl 0
loc 36
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 8 1
A __construct() 0 9 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Granularities;
5
6
use Level23\Druid\Types\Granularity;
7
use Level23\Druid\Collections\IntervalCollection;
8
9
class UniformGranularity extends AbstractGranularity implements GranularityInterface
10
{
11
    protected Granularity $segmentGranularity;
12
13
    /**
14
     * UniformGranularity constructor.
15
     *
16
     * @param string|Granularity $segmentGranularity
17
     * @param string|Granularity $queryGranularity
18
     * @param bool               $rollup
19
     * @param IntervalCollection $intervals
20
     */
21 11
    public function __construct(
22
        string|Granularity $segmentGranularity,
23
        string|Granularity $queryGranularity,
24
        bool $rollup,
25
        IntervalCollection $intervals
26
    ) {
27 11
        parent::__construct($queryGranularity, $rollup, $intervals);
28
29 10
        $this->segmentGranularity = is_string($segmentGranularity) ? Granularity::from(strtolower($segmentGranularity)) : $segmentGranularity;
30
    }
31
32
    /**
33
     * Return the granularity in array format so that we can use it in a druid request.
34
     *
35
     * @return array<string,string|string[]|bool>
36
     */
37 4
    public function toArray(): array
38
    {
39 4
        return [
40 4
            'type'               => 'uniform',
41 4
            'segmentGranularity' => $this->segmentGranularity->value,
42 4
            'queryGranularity'   => $this->queryGranularity->value,
43 4
            'rollup'             => $this->rollup,
44 4
            'intervals'          => $this->intervals->toArray(),
45 4
        ];
46
    }
47
}