Passed
Push — master ( 16ac55...a1819b )
by Teye
05:04
created

UriLookup   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A toArray() 0 21 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
 * @internal
11
 */
12
class UriLookup implements LookupInterface
13
{
14 4
    public function __construct(
15
        protected ParseSpecInterface $parseSpec,
16
        protected string $uri,
17
        protected null|int|string $pollPeriod = null,
18
        protected ?int $maxHeapPercentage = null,
19
        protected bool $injective = false,
20
        protected int $firstCacheTimeoutMs = 0
21
    ) {
22
23 4
    }
24
25 4
    public function toArray(): array
26
    {
27 4
        $response = [
28 4
            'type'               => 'uri',
29 4
            'uri'                => $this->uri,
30 4
            'namespaceParseSpec' => $this->parseSpec->toArray(),
31 4
        ];
32
33 4
        if ($this->pollPeriod !== null) {
34 4
            $response['pollPeriod'] = $this->pollPeriod;
35
        }
36
37 4
        if ($this->maxHeapPercentage !== null) {
38 4
            $response['maxHeapPercentage'] = $this->maxHeapPercentage;
39
        }
40
41 4
        return [
42 4
            'type'                => 'cachedNamespace',
43 4
            'extractionNamespace' => $response,
44 4
            'injective'           => $this->injective,
45 4
            'firstCacheTimeout'   => $this->firstCacheTimeoutMs,
46 4
        ];
47
    }
48
}