Passed
Pull Request — develop_3.0 (#508)
by Adrien
02:50
created

Row::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 1
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 71
    public function __construct(array $cells)
18
    {
19 71
        $this->setCells($cells);
20 71
    }
21
22
    /**
23
     * @return Cell[] $cells
24
     */
25 43
    public function getCells()
26
    {
27 43
        return $this->cells;
28
    }
29
30
    /**
31
     * @param Cell[] $cells
32
     * @return Row
33
     */
34 71
    public function setCells(array $cells)
35
    {
36 71
        $this->cells = [];
37 71
        foreach ($cells as $cell) {
38 47
            $this->addCell($cell);
39
        }
40
41 71
        return $this;
42
    }
43
44
    /**
45
     * @param Cell $cell
46
     * @parma int $cellIndex
47
     * @return Row
48
     */
49 35
    public function setCellAtIndex(Cell $cell, $cellIndex)
50
    {
51 35
        $this->cells[$cellIndex] = $cell;
52
53 35
        return $this;
54
    }
55
56
    /**
57
     * @param Cell $cell
58
     * @return Row
59
     */
60 48
    public function addCell(Cell $cell)
61
    {
62 48
        $this->cells[] = $cell;
63
64 48
        return $this;
65
    }
66
67
    /**
68
     * @return array The row values, as array
69
     */
70
    public function toArray()
71
    {
72 58
        return array_map(function (Cell $cell) {
73 58
            return $cell->getValue();
74 58
        }, $this->cells);
75
    }
76
}
77