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

Row::hasCells()   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
c 0
b 0
f 0
dl 0
loc 4
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\Writer\Common\Entity;
4
5
use Box\Spout\Writer\Common\Entity\Style\Style;
6
use Box\Spout\Writer\Common\Manager\RowManager;
7
8
class Row
9
{
10
    /**
11
     * The cells in this row
12
     * @var Cell[]
13
     */
14
    protected $cells = [];
15
16
    /**
17
     * The row style
18
     * @var Style|null
19
     */
20
    protected $style;
21
22
    /**
23
     * Thw row manager
24
     * @var RowManager
25
     */
26
    protected $rowManager;
27
28
    /**
29
     * Row constructor.
30
     * @param Cell[] $cells
31
     * @param Style|null $style
32
     * @param RowManager $rowManager
33
     */
34 94
    public function __construct(array $cells = [], Style $style = null, RowManager $rowManager)
35
    {
36
        $this
37 94
            ->setCells($cells)
38 94
            ->setStyle($style);
0 ignored issues
show
Bug introduced by
It seems like $style defined by parameter $style on line 34 can be null; however, Box\Spout\Writer\Common\Entity\Row::setStyle() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
39
40 94
        $this->rowManager = $rowManager;
41 94
    }
42
43
    /**
44
     * @return Cell[] $cells
45
     */
46 82
    public function getCells()
47
    {
48 82
        return $this->cells;
49
    }
50
51
    /**
52
     * @param Cell[] $cells
53
     * @return $this
54
     */
55 94
    public function setCells(array $cells)
56
    {
57 94
        $this->cells = [];
58 94
        foreach ($cells as $cell) {
59 89
            $this->addCell($cell);
60
        }
61
62 94
        return $this;
63
    }
64
65
    /**
66
     * @return Style
67
     */
68 62
    public function getStyle()
69
    {
70 62
        if (!isset($this->style)) {
71 46
            $this->setStyle(new Style());
72
        }
73
74 62
        return $this->style;
75
    }
76
77
    /**
78
     * @param Style $style
79
     * @return Row
80
     */
81 94
    public function setStyle($style)
82
    {
83 94
        $this->style = $style;
84
85 94
        return $this;
86
    }
87
88
    /**
89
     * @param Style|null $style
90
     * @return Row
91
     */
92
    public function applyStyle(Style $style = null)
93
    {
94
        $this->rowManager->applyStyle($this, $style);
0 ignored issues
show
Bug introduced by
It seems like $style defined by parameter $style on line 92 can be null; however, Box\Spout\Writer\Common\...owManager::applyStyle() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
95
96
        return $this;
97
    }
98
99
    /**
100
     * @param Cell $cell
101
     * @return Row
102
     */
103 90
    public function addCell(Cell $cell)
104
    {
105 90
        $this->cells[] = $cell;
106
107 90
        return $this;
108
    }
109
110
    /**
111
     * Returns whether a row has cells
112
     *
113
     * @return bool
114
     */
115 71
    public function hasCells()
116
    {
117 71
        return $this->rowManager->hasCells($this);
118
    }
119
120
    /**
121
     * Detect whether this row is considered empty.
122
     * An empty row has either no cells at all - or only empty cells
123
     *
124
     * @return bool
125
     */
126 32
    public function isEmpty()
127
    {
128 32
        return $this->rowManager->isEmpty($this);
129
    }
130
}
131