Passed
Pull Request — develop_3.0 (#434)
by Adrien
03:06
created

RowManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Box\Spout\Writer\Common\Manager;
4
5
use Box\Spout\Writer\Common\Entity\Row;
6
use Box\Spout\Writer\Common\Entity\Style\Style;
7
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
8
9
class RowManager
10
{
11
    /**
12
     * @var StyleMerger
13
     */
14
    protected $styleMerger;
15
16
    /**
17
     * @param StyleMerger $styleMerger
18
     */
19 89
    public function __construct(StyleMerger $styleMerger)
20
    {
21 89
        $this->styleMerger = $styleMerger;
22 89
    }
23
24
    /**
25
     * @param Row $row
26
     * @param Style $style
27
     * @return $this
28
     */
29 1
    public function applyStyle(Row $row, Style $style)
30
    {
31 1
        $mergedStyle = $this->styleMerger->merge($row->getStyle(), $style);
32 1
        $row->setStyle($mergedStyle);
33 1
    }
34
35
    /**
36
     * Returns whether a row has cells
37
     *
38
     * @param Row $row
39
     * @return bool
40
     */
41 75
    public function hasCells(Row $row)
42
    {
43 75
        return count($row->getCells()) !== 0;
44
    }
45
46
    /**
47
     * Detect whether a row is considered empty.
48
     * An empty row has either no cells at all - or only one empty cell
49
     *
50
     * @param Row $row
51
     * @return bool
52
     */
53 35
    public function isEmpty(Row $row)
54
    {
55 35
        $cells = $row->getCells();
56
57 35
        return count($cells) === 0 || (count($cells) === 1 && $cells[0]->isEmpty());
58
    }
59
}
60