Passed
Push — master ( 0e441f...fe9525 )
by Daniel
02:35
created

Header::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 3
rs 9.4285
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\Header;
13
14
15
use RoadBunch\Csv\Exceptions\InvalidHeaderArrayException;
16
17
/**
18
 * Class Header
19
 *
20
 * @author  Dan McAdams
21
 * @package RoadBunch\Csv
22
 */
23
class Header implements HeaderInterface
24
{
25
    /** @var array */
26
    protected $columns;
27
28
    /**
29
     * Header constructor.
30
     *
31
     * @param array $columns array of strings of column names
32
     *
33
     * @throws InvalidHeaderArrayException
34
     */
35 6
    public function __construct(array $columns = [])
36
    {
37 6
        foreach ($columns as $column) {
38 2
            if (!is_string($column)) {
39 2
                throw new InvalidHeaderArrayException('Columns must be array of (string)');
40
            }
41
        }
42 5
        $this->columns = $columns;
43 5
    }
44
45
    /**
46
     * @param string $column
47
     *
48
     * @return void
49
     */
50 3
    public function addColumn(string $column)
51
    {
52 3
        if (!in_array($column, $this->columns)) {
53 3
            $this->columns[] = $column;
54
        }
55 3
    }
56
57
    /**
58
     * @return array
59
     */
60 4
    public function getColumns(): array
61
    {
62 4
        return $this->columns;
63
    }
64
}
65