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

KafkaLookup::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 5
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Lookups;
5
6
/**
7
 * @see https://druid.apache.org/docs/latest/querying/kafka-extraction-namespace
8
 * @internal
9
 */
10
class KafkaLookup implements LookupInterface
11
{
12
    /**
13
     * @param string                   $kafkaTopic      The Kafka topic to read the data from
14
     * @param string|array<int,string> $servers
15
     * @param array<string,scalar>     $kafkaProperties Kafka consumer properties
16
     * @param int                      $connectTimeout  How long to wait for an initial connection
17
     * @param bool                     $isOneToOne      The map is a one-to-one (like injective)
18
     */
19 2
    public function __construct(
20
        protected string $kafkaTopic,
21
        protected string|array $servers,
22
        protected array $kafkaProperties = [],
23
        protected int $connectTimeout = 0,
24
        protected bool $isOneToOne = false
25
    ) {
26 2
        $this->kafkaProperties['bootstrap.servers'] =
27 2
            is_array($this->servers)
28 1
                ? implode(',', $this->servers)
29 2
                : $this->servers;
30
    }
31
32
    /**
33
     * @return array<string,string|array<string,scalar>|int|bool>
34
     */
35 2
    public function toArray(): array
36
    {
37 2
        return [
38 2
            'type'            => 'kafka',
39 2
            'kafkaTopic'      => $this->kafkaTopic,
40 2
            'kafkaProperties' => $this->kafkaProperties,
41 2
            'connectTimeout'  => $this->connectTimeout,
42 2
            'isOneToOne'      => $this->isOneToOne,
43 2
        ];
44
    }
45
}