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

CsvParseSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 46
ccs 16
cts 16
cp 1
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
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
}