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

CellManager   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

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
     * @param StyleMerger $styleMerger
18
     */
19
    public function __construct(StyleMerger $styleMerger)
20
    {
21
        $this->styleMerger = $styleMerger;
22
    }
23
24
    /**
25
     * Merges a Style into a cell's Style.
26
     *
27
     * @param Cell $cell
28
     * @param Style $style
29
     * @return $this
30
     */
31
    public function applyStyle(Cell $cell, Style $style)
32
    {
33
        $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...
34
        $cell->setStyle($mergedStyle);
35
    }
36
}
37