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

KafkaLookup   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A toArray() 0 8 1
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
}