Passed
Pull Request — master (#38)
by Teye
06:17
created

TsvInputFormat::toArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\InputFormats;
5
6
class TsvInputFormat extends CsvInputFormat
7
{
8
    protected ?string $delimiter;
9
10
    /**
11
     * @param array<string>|null $columns               Specifies the columns of the data. The columns should be in the
12
     *                                                  same order with the columns of your data.
13
     * @param string|null        $delimiter             A custom delimiter for data values.
14
     * @param string|null        $listDelimiter         A custom delimiter for multi-value dimensions.
15
     * @param bool|null          $findColumnsFromHeader If this is set, the task will find the column names from the
16
     *                                                  header row. Note that skipHeaderRows will be applied before
17
     *                                                  finding column names from the header. For example, if you set
18
     *                                                  skipHeaderRows to 2 and findColumnsFromHeader to true, the task
19
     *                                                  will skip the first two lines and then extract column
20
     *                                                  information from the third line. columns will be ignored if
21
     *                                                  this is set to true.
22
     * @param int                $skipHeaderRows        If this is set, the task will skip the first skipHeaderRows
23
     *                                                  rows.
24
     */
25 7
    public function __construct(
26
        array $columns = null,
27
        string $delimiter = null,
28
        string $listDelimiter = null,
29
        bool $findColumnsFromHeader = null,
30
        int $skipHeaderRows = 0
31
    ) {
32 7
        $this->delimiter = $delimiter;
33 7
        parent::__construct($columns, $listDelimiter, $findColumnsFromHeader, $skipHeaderRows);
34
    }
35
36
    /**
37
     * Return the TsvInputFormat so that it can be used in a druid query.
38
     *
39
     * @return array<string,string|string[]|bool|int>
40
     */
41 7
    public function toArray(): array
42
    {
43 7
        $result         = parent::toArray();
44 7
        $result['type'] = 'tsv';
45
46 7
        if ($this->delimiter !== null) {
47 3
            $result['delimiter'] = $this->delimiter;
48
        }
49
50 7
        return $result;
51
    }
52
}