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

CsvParseSpec::toArray()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5

Importance

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