Passed
Pull Request — master (#63)
by Teye
14:30 queued 09:12
created

UriLookup::toArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 21
ccs 15
cts 15
cp 1
rs 9.8333
cc 3
nc 4
nop 0
crap 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Lookups;
5
6
use Level23\Druid\Lookups\ParseSpecs\ParseSpecInterface;
7
8
/**
9
 * @see https://druid.apache.org/docs/latest/querying/lookups-cached-global#uri-lookup
10
 */
11
class UriLookup implements LookupInterface
12
{
13 4
    public function __construct(
14
        protected ParseSpecInterface $parseSpec,
15
        protected string $uri,
16
        protected null|int|string $pollPeriod = null,
17
        protected ?int $maxHeapPercentage = null,
18
        protected bool $injective = false,
19
        protected int $firstCacheTimeoutMs = 0
20
    ) {
21
22 4
    }
23
24 4
    public function toArray(): array
25
    {
26 4
        $response = [
27 4
            'type'               => 'uri',
28 4
            'uri'                => $this->uri,
29 4
            'namespaceParseSpec' => $this->parseSpec->toArray(),
30 4
        ];
31
32 4
        if ($this->pollPeriod !== null) {
33 4
            $response['pollPeriod'] = $this->pollPeriod;
34
        }
35
36 4
        if ($this->maxHeapPercentage !== null) {
37 4
            $response['maxHeapPercentage'] = $this->maxHeapPercentage;
38
        }
39
40 4
        return [
41 4
            'type'                => 'cachedNamespace',
42 4
            'extractionNamespace' => $response,
43 4
            'injective'           => $this->injective,
44 4
            'firstCacheTimeout'   => $this->firstCacheTimeoutMs,
45 4
        ];
46
    }
47
}