Gradient::appendStop()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
namespace nstdio\svg\gradient;
3
4
use nstdio\svg\ElementInterface;
5
use nstdio\svg\SVGElement;
6
use nstdio\svg\util\Identifier;
7
8
/**
9
 * Class Gradient
10
 *
11
 * @package nstdio\svg\gradient
12
 * @author  Edgar Asatryan <[email protected]>
13
 */
14
abstract class Gradient extends SVGElement
15
{
16
    const LINEAR = 'linear';
17
18
    const RADIAL = 'radial';
19
20
    /**
21
     * Gradient constructor.
22
     *
23
     * @param ElementInterface $parent
24
     * @param null|string      $id
25
     */
26 38
    public function __construct(ElementInterface $parent, $id = null)
27
    {
28 38
        $defs = self::getDefs($parent);
29 38
        parent::__construct($defs);
0 ignored issues
show
Bug introduced by
It seems like $defs defined by self::getDefs($parent) on line 28 can be null; however, nstdio\svg\SVGElement::__construct() 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...
30
31 38
        $this->id = $id === null ? Identifier::random('__gradient', 4) : $id;
32 38
    }
33
34
    /**
35
     * Multiply argument can be passed.
36
     *
37
     * @param Stop $stop
38
     */
39 36
    public function appendStop(Stop $stop)
0 ignored issues
show
Unused Code introduced by
The parameter $stop is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
    {
41 36
        $stop = func_get_args();
42 36
        foreach ($stop as $item) {
43 36
            $this->append($item);
44 36
        }
45
    }
46
}