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

CsvParseSpec::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 7
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 5
crap 1
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
}