Passed
Pull Request — master (#63)
by Teye
14:30 queued 09:12
created

TsvParseSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A toArray() 0 25 6
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Lookups\ParseSpecs;
5
6
class TsvParseSpec implements ParseSpecInterface
7
{
8
    /**
9
     * Specify the TSV parse spec.
10
     *
11
     * @param array<int,string>|null $columns
12
     * @param string|null            $keyColumn
13
     * @param string|null            $valueColumn
14
     * @param string|null            $delimiter
15
     * @param string|null            $listDelimiter
16
     * @param bool                   $hasHeaderRow
17
     * @param int                    $skipHeaderRows
18
     */
19 1
    public function __construct(
20
        protected null|array $columns,
21
        protected ?string $keyColumn = null,
22
        protected ?string $valueColumn = null,
23
        protected ?string $delimiter = null,
24
        protected ?string $listDelimiter = null,
25
        protected bool $hasHeaderRow = false,
26
        protected int $skipHeaderRows = 0
27
    ) {
28
29 1
    }
30
31
    /**
32
     * @return array<string,bool|array<int,string>|string|int|null>
33
     */
34 1
    public function toArray(): array
35
    {
36 1
        $response = [
37 1
            'format'       => 'tsv',
38 1
            'columns'      => $this->columns,
39 1
            'hasHeaderRow' => $this->hasHeaderRow,
40 1
        ];
41
42 1
        if ($this->keyColumn !== null) {
43 1
            $response['keyColumn'] = $this->keyColumn;
44
        }
45 1
        if ($this->valueColumn !== null) {
46 1
            $response['valueColumn'] = $this->valueColumn;
47
        }
48 1
        if ($this->delimiter !== null) {
49 1
            $response['delimiter'] = $this->delimiter;
50
        }
51 1
        if ($this->listDelimiter !== null) {
52 1
            $response['listDelimiter'] = $this->listDelimiter;
53
        }
54 1
        if ($this->skipHeaderRows !== null) {
55 1
            $response['skipHeaderRows'] = $this->skipHeaderRows;
56
        }
57
58 1
        return $response;
59
    }
60
}