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

CellManager   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 29
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A applyStyle() 0 5 1
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
}