Test Failed
Pull Request — master (#64)
by Teye
15:39
created

TsvParseSpec::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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