Passed
Pull Request — master (#63)
by Teye
14:30 queued 09:12
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
 */
9
class KafkaLookup implements LookupInterface
10
{
11
    /**
12
     * @param string                   $kafkaTopic      The Kafka topic to read the data from
13
     * @param string|array<int,string> $servers
14
     * @param array<string,scalar>     $kafkaProperties Kafka consumer properties
15
     * @param int                      $connectTimeout  How long to wait for an initial connection
16
     * @param bool                     $isOneToOne      The map is a one-to-one (like injective)
17
     */
18 2
    public function __construct(
19
        protected string $kafkaTopic,
20
        protected string|array $servers,
21
        protected array $kafkaProperties = [],
22
        protected int $connectTimeout = 0,
23
        protected bool $isOneToOne = false
24
    ) {
25 2
        $this->kafkaProperties['bootstrap.servers'] =
26 2
            is_array($this->servers)
27 1
                ? implode(',', $this->servers)
28 2
                : $this->servers;
29
    }
30
31
    /**
32
     * @return array<string,string|array<string,scalar>|int|bool>
33
     */
34 2
    public function toArray(): array
35
    {
36 2
        return [
37 2
            'type'            => 'kafka',
38 2
            'kafkaTopic'      => $this->kafkaTopic,
39 2
            'kafkaProperties' => $this->kafkaProperties,
40 2
            'connectTimeout'  => $this->connectTimeout,
41 2
            'isOneToOne'      => $this->isOneToOne,
42 2
        ];
43
    }
44
}