Failed Conditions
Pull Request — develop_3.0 (#434)
by Hura
04:53 queued 02:03
created

Row::setStyle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

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 3
nc 1
nop 1
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 array
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 87
    public function __construct(array $cells = [], Style $style = null, RowManager $rowManager)
35
    {
36
        $this
37 87
            ->setCells($cells)
38 87
            ->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 87
        $this->rowManager = $rowManager;
41 87
    }
42
43
    /**
44
     * @return Cell[] $cells
45
     */
46 75
    public function getCells()
47
    {
48 75
        return $this->cells;
49
    }
50
51
    /**
52
     * @param array $cells
53
     * @return $this
54
     */
55 87
    public function setCells(array $cells)
56
    {
57 87
        $this->cells = [];
58 87
        foreach ($cells as $cell) {
59 84
            $this->addCell($cell);
60
        }
61
62 87
        return $this;
63
    }
64
65
    /**
66
     * @return Style
67
     */
68 61
    public function getStyle()
69
    {
70 61
        if (!isset($this->style)) {
71 45
            $this->setStyle(new Style());
72
        }
73
74 61
        return $this->style;
75
    }
76
77
    /**
78
     * @param Style $style
79
     * @return Row
80
     */
81 87
    public function setStyle($style)
82
    {
83 87
        $this->style = $style;
84
85 87
        return $this;
86
    }
87
88
    /**
89
     * @param Style $style|null
0 ignored issues
show
Bug introduced by
There is no parameter named $style|null. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
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 85
    public function addCell(Cell $cell)
104
    {
105 85
        $this->cells[] = $cell;
106
107 85
        return $this;
108
    }
109
110
    /**
111
     * Detect whether this row is considered empty.
112
     * An empty row has either no cells at all - or only empty cells
113
     *
114
     * @return bool
115
     */
116 70
    public function isEmpty()
117
    {
118 70
        return $this->rowManager->isEmpty($this);
119
    }
120
}
121