Descriptive   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
1
<?php
2
namespace nstdio\svg\desc;
3
use nstdio\svg\ElementInterface;
4
use nstdio\svg\SVGElement;
5
6
/**
7
 * Class Descriptive
8
 *
9
 * @package nstdio\svg\desc
10
 * @author  Edgar Asatryan <[email protected]>
11
 */
12
abstract class Descriptive extends SVGElement
13
{
14 3
    public function __construct(ElementInterface $parent, $value)
15
    {
16 3
        parent::__construct($parent);
17
18 3
        $this->getElement()->setNodeValue($value);
0 ignored issues
show
Bug introduced by
The method setNodeValue does only exist in nstdio\svg\XMLDocumentInterface, but not in DOMElement and nstdio\sv...iner\ContainerInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
19
    }
20
}