Test Failed
Push — master ( c6f077...3d80e3 )
by Daniel
01:58
created

Header::getColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * This file is part of the Csv-Machine package.
5
 *
6
 * (c) Dan McAdams <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace RoadBunch\Csv;
13
14
15
use RoadBunch\Csv\Exceptions\InvalidHeaderArrayException;
16
use RoadBunch\Csv\Interfaces\HeaderInterface;
17
18
/**
19
 * Class Header
20
 *
21
 * @author  Dan McAdams
22
 * @package RoadBunch\Csv
23
 */
24
class Header implements HeaderInterface
25
{
26
    protected $columns;
27
28
    /**
29
     * Header constructor.
30
     *
31
     * @param array $columns
32
     *
33
     * @throws InvalidHeaderArrayException
34
     */
35
    public function __construct(array $columns = [])
36
    {
37
        foreach ($columns as $column) {
38
            if (!is_string($column)) {
39
                throw new InvalidHeaderArrayException('Columns must be array of (string)');
40
            }
41
        }
42
        $this->columns = $columns;
43
    }
44
45
    /**
46
     * @param string $column
47
     *
48
     * @return void
49
     */
50
    public function addColumn(string $column)
51
    {
52
        if (!in_array($column, $this->columns)) {
53
            $this->columns[] = $column;
54
        }
55
    }
56
57
    /**
58
     * @return array
59
     */
60
    public function getColumns(): array
61
    {
62
        return $this->columns;
63
    }
64
}
65