Failed Conditions
Pull Request — develop_3.0 (#507)
by Adrien
02:47
created

Row::setCells()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Box\Spout\Reader\Common\Entity;
4
5
class Row
6
{
7
    /**
8
     * The cells in this row
9
     * @var Cell[]
10
     */
11
    protected $cells = [];
12
13
    /**
14
     * Row constructor.
15
     * @param Cell[] $cells
16
     */
17 24
    public function __construct(array $cells)
18
    {
19 24
        $this->setCells($cells);
20 24
    }
21
22
    /**
23
     * @return Cell[] $cells
24
     */
25
    public function getCells()
26
    {
27
        return $this->cells;
28
    }
29
30
    /**
31
     * @param Cell[] $cells
32
     * @return $this
33
     */
34 24
    public function setCells(array $cells)
35
    {
36 24
        $this->cells = [];
37 24
        foreach ($cells as $cell) {
38 24
            $this->addCell($cell);
39
        }
40
41 24
        return $this;
42
    }
43
44
    /**
45
     * @param Cell $cell
46
     * @return Row
47
     */
48 24
    public function addCell(Cell $cell)
49
    {
50 24
        $this->cells[] = $cell;
51
52 24
        return $this;
53
    }
54
55
    /**
56
     * @return array The row values, as array
57
     */
58
    public function toArray()
59
    {
60 24
        return array_map(function (Cell $cell) {
61 24
            return $cell->getValue();
62 24
        }, $this->cells);
63
    }
64
}
65