Passed
Pull Request — master (#63)
by Teye
05:26
created

UriPrefixLookup   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 16
c 1
b 0
f 0
dl 0
loc 60
ccs 19
cts 19
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A toArray() 0 25 4
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 UriPrefixLookup implements LookupInterface
13
{
14
    /**
15
     * @param ParseSpecInterface $parseSpec
16
     * @param string             $uriPrefix
17
     * @param string|null        $fileRegex
18
     * @param string|null        $pollPeriod          The pollPeriod value specifies the period in ISO 8601 format
19
     *                                                between checks for replacement data for the lookup. For example
20
     *                                                PT15M. When not given, it is only once. If the source of the
21
     *                                                lookup is capable of providing a timestamp, the lookup will only
22
     *                                                be updated if it has changed since the prior tick of pollPeriod.
23
     *                                                A value of 0, an absent parameter, or null all mean populate once
24
     *                                                and do not attempt to look for new data later. Whenever an poll
25
     *                                                occurs, the updating system will look for a file with the most
26
     *                                                recent timestamp and assume that one with the most recent data
27
     *                                                set, replacing the local cache of the lookup data.
28
     * @param int|null           $maxHeapPercentage
29
     * @param bool               $injective           If the underlying map is injective (keys and values are unique)
30
     *                                                then optimizations can occur internally by setting this to true
31
     * @param int                $firstCacheTimeoutMs How long to wait (in ms) for the first run of the cache to
32
     *                                                populate. 0 indicates to not  wait
33
     *
34
     */
35 1
    public function __construct(
36
        protected ParseSpecInterface $parseSpec,
37
        protected string $uriPrefix,
38
        protected ?string $fileRegex = null,
39
        protected ?string $pollPeriod = null,
40
        protected ?int $maxHeapPercentage = null,
41
        protected bool $injective = false,
42
        protected int $firstCacheTimeoutMs = 0
43
    ) {
44
45 1
    }
46
47 1
    public function toArray(): array
48
    {
49 1
        $response = [
50 1
            'type'               => 'uri',
51 1
            'uriPrefix'          => $this->uriPrefix,
52 1
            'namespaceParseSpec' => $this->parseSpec->toArray(),
53 1
        ];
54
55 1
        if ($this->fileRegex !== null) {
56 1
            $response['fileRegex'] = $this->fileRegex;
57
        }
58
59 1
        if ($this->pollPeriod !== null) {
60 1
            $response['pollPeriod'] = $this->pollPeriod;
61
        }
62
63 1
        if ($this->maxHeapPercentage !== null) {
64 1
            $response['maxHeapPercentage'] = $this->maxHeapPercentage;
65
        }
66
67 1
        return [
68 1
            'type'                => 'cachedNamespace',
69 1
            'extractionNamespace' => $response,
70 1
            'injective'           => $this->injective,
71 1
            'firstCacheTimeout'   => $this->firstCacheTimeoutMs,
72 1
        ];
73
    }
74
}