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

Header   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A addColumn() 0 4 2
A getColumns() 0 3 1
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