Completed
Push — master ( fb3943...fbbc4e )
by Edgar
04:02
created

DOMNode::isLoaded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace nstdio\svg\xml;
3
4
use nstdio\svg\util\KeyValueWriter;
5
use nstdio\svg\XMLDocumentInterface;
6
7
/**
8
 * Class DOMNode
9
 *
10
 * @package nstdio\svg\xml
11
 * @author  Edgar Asatryan <[email protected]>
12
 */
13
abstract class DOMNode implements XMLDocumentInterface
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    abstract public function setNodeValue($value);
19
20
    /**
21
     * @inheritdoc
22
     */
23
    abstract public function getNodeValue();
24
25
    /**
26
     * @inheritdoc
27
     */
28 8
    public function attributes(array $except = [])
29
    {
30 8
        return KeyValueWriter::allAttributes($this->getElement(), $except);
0 ignored issues
show
Bug introduced by
It seems like $this->getElement() targeting nstdio\svg\xml\DOMNode::getElement() can also be of type object<nstdio\svg\XMLDocumentInterface>; however, nstdio\svg\util\KeyValueWriter::allAttributes() does only seem to accept object<DOMNode>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    abstract public function getElement();
37
38
    /**
39
     * @inheritdoc
40
     */
41 149
    public function setAttribute($name, $value = null)
42
    {
43 149
        $this->getElement()->setAttribute($name, $value);
0 ignored issues
show
Bug introduced by
The method setAttribute does only exist in DOMElement and nstdio\svg\XMLDocumentInterface, but not in DOMDocument.

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...
44 149
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49 109
    public function getAttribute($name)
50
    {
51 109
        return $this->getElement()->getAttribute($name);
0 ignored issues
show
Bug introduced by
The method getAttribute does only exist in DOMElement and nstdio\svg\XMLDocumentInterface, but not in DOMDocument.

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...
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57 149
    public function setAttributeNS($namespaceURI, $qualifiedName, $value)
58
    {
59 149
        $this->getElement()->setAttributeNS($namespaceURI, $qualifiedName, $value);
0 ignored issues
show
Bug introduced by
The method setAttributeNS does only exist in DOMElement and nstdio\svg\XMLDocumentInterface, but not in DOMDocument.

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...
60 149
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65 81
    public function getAttributeNS($namespaceURI, $localName)
66
    {
67 81
        return $this->getElement()->getAttributeNS($namespaceURI, $localName);
0 ignored issues
show
Bug introduced by
The method getAttributeNS does only exist in DOMElement and nstdio\svg\XMLDocumentInterface, but not in DOMDocument.

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...
68
    }
69
70 149
    public function appendChild(XMLDocumentInterface $newNode)
71
    {
72 149
        $this->getElement()->appendChild($newNode->getElement());
0 ignored issues
show
Bug introduced by
It seems like $newNode->getElement() targeting nstdio\svg\XMLDocumentInterface::getElement() can also be of type object<DOMDocument> or object<DOMElement>; however, nstdio\svg\XMLDocumentInterface::appendChild() does only seem to accept object<nstdio\svg\XMLDocumentInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
73 149
    }
74
75
    /**
76
     * @inheritdoc
77
     */
78 149
    public function createElement($name, $value = null)
79
    {
80
        // on PHP 5.4.* createElement method with null parameter will create empty DOMText object as child of created element
81 149
        $element = $value === null ? $this->getElement()->createElement($name) : $this->getElement()->createElement($name, $value);
0 ignored issues
show
Bug introduced by
The method createElement does only exist in DOMDocument and nstdio\svg\XMLDocumentInterface, but not in DOMElement.

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...
82
83 149
        return new DOMElementWrapper($element);
84
    }
85
86
    /**
87
     * @inheritdoc
88
     */
89
    public function createElementNS($namespaceURI, $qualifiedName, $value = null)
90
    {
91
        return $this->getElement()->createElementNS($namespaceURI, $qualifiedName, $value);
0 ignored issues
show
Bug introduced by
The method createElementNS does only exist in DOMDocument and nstdio\svg\XMLDocumentInterface, but not in DOMElement.

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...
92
    }
93
94
    /**
95
     * @inheritdoc
96
     */
97 9
    public function removeNode(XMLDocumentInterface $child)
98
    {
99 9
        return $this->getElement()->removeChild($child->getElement());
0 ignored issues
show
Bug introduced by
The method removeChild does only exist in DOMDocument and DOMElement, but not in nstdio\svg\XMLDocumentInterface.

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...
100
    }
101
102
    /**
103
     * @inheritdoc
104
     */
105 62
    public function saveHTML()
106
    {
107 62
        return $this->getElement()->saveHTML();
0 ignored issues
show
Bug introduced by
The method saveHTML does only exist in DOMDocument and nstdio\svg\XMLDocumentInterface, but not in DOMElement.

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...
108
    }
109
110 2
    public function saveXML($formatOutput)
111
    {
112 2
        return $this->getElement()->saveXML();
0 ignored issues
show
Bug introduced by
The call to saveXML() misses a required argument $formatOutput.

This check looks for function calls that miss required arguments.

Loading history...
Bug introduced by
The method saveXML does only exist in DOMDocument and nstdio\svg\XMLDocumentInterface, but not in DOMElement.

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...
113
    }
114
115
    /**
116
     * @inheritdoc
117
     */
118 149
    public static function isLoaded()
119
    {
120 149
        return extension_loaded('dom');
121
    }
122
123 1
    public function __debugInfo()
124
    {
125
        return [
126 1
            'nodeName' => $this->getElement()->nodeName,
127 1
        ];
128
    }
129
}