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

CsvParseSpec::toArray()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5.009

Importance

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