Passed
Push — develop_3.0 ( 102e17...4d1d1c )
by Adrien
02:57
created

Row::getNumCells()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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