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

CellManager::applyStyle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Box\Spout\Writer\Common\Manager;
4
5
use Box\Spout\Writer\Common\Entity\Cell;
6
use Box\Spout\Writer\Common\Entity\Style\Style;
7
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
8
9
class CellManager
10
{
11
    /**
12
     * @var StyleMerger
13
     */
14
    protected $styleMerger;
15
16
    /**
17
     * CellManager constructor.
18
     * @param StyleMerger $styleMerger
19
     */
20
    public function __construct(StyleMerger $styleMerger)
21
    {
22
        $this->styleMerger = $styleMerger;
23
    }
24
25
    /**
26
     * Merges a Style into a cells Style.
27
     *
28
     * @param Cell $cell
29
     * @param Style $style
30
     * @return $this
31
     */
32
    public function applyStyle(Cell $cell, Style $style)
33
    {
34
        $mergedStyle = $this->styleMerger->merge($cell->getStyle(), $style);
0 ignored issues
show
Bug introduced by
It seems like $cell->getStyle() can be null; however, merge() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
35
        $cell->setStyle($mergedStyle);
36
    }
37
}