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

TsvParseSpec::toArray()   A

Complexity

Conditions 6
Paths 32

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 6.1979

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 25
ccs 14
cts 17
cp 0.8235
rs 9.2222
cc 6
nc 32
nop 0
crap 6.1979
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
}