Completed
Pull Request — develop_3.0 (#535)
by Hura
04:14
created

Row   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 2
dl 0
loc 117
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getCells() 0 4 1
A setCells() 0 9 2
A setCellAtIndex() 0 6 1
A addCell() 0 6 1
A getNumCells() 0 4 1
A getStyle() 0 4 1
A setStyle() 0 6 2
A toArray() 0 6 2
A getCellAtIndex() 0 4 2
1
<?php
2
3
namespace Box\Spout\Common\Entity;
4
5
use Box\Spout\Common\Entity\Style\Style;
6
7
class Row
8
{
9
    /**
10
     * The cells in this row
11
     * @var Cell[]
12
     */
13
    protected $cells = [];
14
15
    /**
16
     * The row style
17
     * @var Style
18
     */
19
    protected $style;
20
21
    /**
22
     * Row constructor.
23
     * @param Cell[] $cells
24
     * @param Style|null $style
25
     */
26 172
    public function __construct(array $cells, $style)
27
    {
28
        $this
29 172
            ->setCells($cells)
30 172
            ->setStyle($style);
31 172
    }
32
33
    /**
34
     * @return Cell[] $cells
35
     */
36 129
    public function getCells()
37
    {
38 129
        return $this->cells;
39
    }
40
41
    /**
42
     * @param Cell[] $cells
43
     * @return Row
44
     */
45 172
    public function setCells(array $cells)
46
    {
47 172
        $this->cells = [];
48 172
        foreach ($cells as $cell) {
49 120
            $this->addCell($cell);
50
        }
51
52 172
        return $this;
53
    }
54
55
    /**
56
     * @param Cell $cell
57
     * @param int $cellIndex
58
     * @return Row
59
     */
60 36
    public function setCellAtIndex(Cell $cell, $cellIndex)
61
    {
62 36
        $this->cells[$cellIndex] = $cell;
63
64 36
        return $this;
65
    }
66
67
    /**
68
     * @param int $cellIndex
69
     * @return Cell|null
70
     */
71 1
    public function getCellAtIndex($cellIndex)
72
    {
73 1
        return isset($this->cells[$cellIndex]) ? $this->cells[$cellIndex] : null;
74
    }
75
76
    /**
77
     * @param Cell $cell
78
     * @return Row
79
     */
80 146
    public function addCell(Cell $cell)
81
    {
82 146
        $this->cells[] = $cell;
83
84 146
        return $this;
85
    }
86
87
    /**
88
     * @return int
89
     */
90 105
    public function getNumCells()
91
    {
92 105
        return count($this->cells);
93
    }
94
95
    /**
96
     * @return Style
97
     */
98 53
    public function getStyle()
99
    {
100 53
        return $this->style;
101
    }
102
103
    /**
104
     * @param Style|null $style
105
     * @return Row
106
     */
107 172
    public function setStyle($style)
108
    {
109 172
        $this->style = $style ?: new Style();
110
111 172
        return $this;
112
    }
113
114
    /**
115
     * @return array The row values, as array
116
     */
117
    public function toArray()
118
    {
119 82
        return array_map(function (Cell $cell) {
120 82
            return !$cell->isError() ? $cell->getValue() : null;
121 82
        }, $this->cells);
122
    }
123
}
124