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

Row::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 3
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
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
8
9
class Row
10
{
11
    /**
12
     * The cells in this row
13
     * @var array
14
     */
15
    protected $cells = [];
16
17
    /**
18
     * The row style
19
     * @var null|Style
20
     */
21
    protected $style = null;
22
23
    /**
24
     * Thw row manager
25
     * @var RowManager
26
     */
27
    protected $rowManager;
28
29
    /**
30
     * Row constructor.
31
     * @param Cell[] $cells
32
     * @param Style|null $style
33
     * @param RowManager $rowManager
34
     */
35 87
    public function __construct(array $cells = [], Style $style = null, RowManager $rowManager)
36
    {
37
        $this
38 87
            ->setCells($cells)
39 87
            ->setStyle($style);
0 ignored issues
show
Bug introduced by
It seems like $style defined by parameter $style on line 35 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...
40
41 87
        $this->rowManager = $rowManager;
42 87
    }
43
44
    /**
45
     * @return Cell[] $cells
46
     */
47 75
    public function getCells()
48
    {
49 75
        return $this->cells;
50
    }
51
52
    /**
53
     * @param array $cells
54
     * @return $this
55
     */
56 87
    public function setCells(array $cells)
57
    {
58 87
        $this->cells = [];
59 87
        foreach ($cells as $cell) {
60 84
            $this->addCell($cell);
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 61
        return $this->style;
74
    }
75
76
    /**
77
     * @param Style $style
78
     * @return Row
79
     */
80 87
    public function setStyle($style)
81
    {
82 87
        $this->style = $style;
83 87
        return $this;
84
    }
85
86
    /**
87
     * @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...
88
     * @return Row
89
     */
90
    public function applyStyle(Style $style = null)
91
    {
92
        $this->rowManager->applyStyle($this, $style);
0 ignored issues
show
Bug introduced by
It seems like $style defined by parameter $style on line 90 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...
93
        return $this;
94
    }
95
96
    /**
97
     * @param Cell $cell
98
     * @return Row
99
     */
100 85
    public function addCell(Cell $cell)
101
    {
102 85
        $this->cells[] = $cell;
103 85
        return $this;
104
    }
105
106
    /**
107
     * Detect whether this row is considered empty.
108
     * An empty row has either no cells at all - or only empty cells
109
     *
110
     * @return bool
111
     */
112 70
    public function isEmpty()
113
    {
114 70
        return $this->rowManager->isEmpty($this);
115
    }
116
}
117