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

Row   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 2

Test Coverage

Coverage 89.66%

Importance

Changes 0
Metric Value
wmc 11
c 0
b 0
f 0
lcom 3
cbo 2
dl 0
loc 123
ccs 26
cts 29
cp 0.8966
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getCells() 0 4 1
A setCells() 0 9 2
A getStyle() 0 8 2
A setStyle() 0 6 1
A applyStyle() 0 6 1
A addCell() 0 6 1
A hasCells() 0 4 1
A isEmpty() 0 4 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 $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 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