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

CsvParseSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 2
b 0
f 0
dl 0
loc 46
ccs 15
cts 16
cp 0.9375
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A toArray() 0 22 5
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
}