Failed Conditions
Pull Request — master (#738)
by
unknown
02:18
created

Row::setHeight()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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 height (default is 15)
23
     * @var string
24
     */
25
    protected $height = "15";
26
27
    /**
28
     * Row constructor.
29
     * @param Cell[] $cells
30
     * @param Style|null $style
31
     */
32 190
    public function __construct(array $cells, $style)
33
    {
34
        $this
35 190
            ->setCells($cells)
36 190
            ->setStyle($style);
37 190
    }
38
39
    /**
40
     * @return Cell[] $cells
41
     */
42 146
    public function getCells()
43
    {
44 146
        return $this->cells;
45
    }
46
47
    /**
48
     * @param Cell[] $cells
49
     * @return Row
50
     */
51 190
    public function setCells(array $cells)
52
    {
53 190
        $this->cells = [];
54 190
        foreach ($cells as $cell) {
55 135
            $this->addCell($cell);
56
        }
57
58 190
        return $this;
59
    }
60
61
    /**
62
     * @param Cell $cell
63
     * @param int $cellIndex
64
     * @return Row
65
     */
66 38
    public function setCellAtIndex(Cell $cell, $cellIndex)
67
    {
68 38
        $this->cells[$cellIndex] = $cell;
69
70 38
        return $this;
71
    }
72
73
    /**
74
     * @param int $cellIndex
75
     * @return Cell|null
76
     */
77 2
    public function getCellAtIndex($cellIndex)
78
    {
79 2
        return $this->cells[$cellIndex] ?? null;
80
    }
81
82
    /**
83
     * @param Cell $cell
84
     * @return Row
85
     */
86 162
    public function addCell(Cell $cell)
87
    {
88 162
        $this->cells[] = $cell;
89
90 162
        return $this;
91
    }
92
93
    /**
94
     * @return int
95
     */
96 123
    public function getNumCells()
97
    {
98
        // When using "setCellAtIndex", it's possible to
99
        // have "$this->cells" contain holes.
100 123
        if (empty($this->cells)) {
101 9
            return 0;
102
        }
103
104 117
        return \max(\array_keys($this->cells)) + 1;
105
    }
106
107
    /**
108
     * @return Style
109
     */
110 68
    public function getStyle()
111
    {
112 68
        return $this->style;
113
    }
114
115
    /**
116
     * @param Style|null $style
117
     * @return Row
118
     */
119 190
    public function setStyle($style)
120
    {
121 190
        $this->style = $style ?: new Style();
122
123 190
        return $this;
124
    }
125
126
    /**
127
     * @return array The row values, as array
128
     */
129 84
    public function toArray()
130
    {
131
        return \array_map(function (Cell $cell) {
132 84
            return $cell->getValue();
133 84
        }, $this->cells);
134
    }
135
136
    /**
137
     * Set row height
138
     * @param String $height
139
     * @return Row
140
     */
141
    public function setHeight($height)
142
    {
143
        $this->height = $height;
144
        return $this;
145
    }
146
147
    /**
148
     * Returns row height
149
     * @return String
150
     */
151 35
    public function getHeight()
152
    {
153 35
        return $this->height;
154
    }
155
}
156