Completed
Push — master ( 3a9efb...7c66eb )
by Edgar
05:49 queued 02:25
created

DOMWrapper   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 44.12%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 15
c 4
b 0
f 1
lcom 1
cbo 4
dl 0
loc 90
ccs 15
cts 34
cp 0.4412
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A setAttribute() 0 4 1
A getAttribute() 0 4 1
A setAttributeNS() 0 4 1
A getAttributeNS() 0 4 1
A appendChild() 0 4 1
A createElement() 0 7 2
A createElementNS() 0 4 1
A isLoaded() 0 4 1
A saveHTML() 0 4 1
A getElement() 0 4 1
A setNodeValue() 0 4 1
A getNodeValue() 0 4 1
A removeNode() 0 4 1
A __construct() 0 6 1
1
<?php
2
namespace nstdio\svg\xml;
3
4
use DOMDocument;
5
use nstdio\svg\Base;
6
use nstdio\svg\traits\ElementTrait;
7
use nstdio\svg\XMLDocumentInterface;
8
9
/**
10
 * Class DomWrapper
11
 *
12
 * @package nstdio\svg\xml
13
 * @author  Edgar Asatryan <[email protected]>
14
 */
15
final class DOMWrapper implements XMLDocumentInterface
16
{
17
    use ElementTrait;
18
19
    /**
20
     * @var DOMDocument
21
     */
22
    private $dom;
23
24 121
    public function __construct()
25 1
    {
26 121
        $this->dom = new DOMDocument(Base::DOM_VERSION, Base::DOM_ENCODING);
27 121
        $this->dom->xmlStandalone = false;
28 121
        $this->dom->formatOutput = true;
29 121
    }
30
31
    public function setAttribute($name, $value = null)
32
    {
33
        $this->dom->documentElement->setAttribute($name, $value);
34
    }
35
36
    public function getAttribute($name)
37
    {
38
        return $this->dom->documentElement->getAttribute($name);
39
    }
40
41
    public function setAttributeNS($namespaceURI, $qualifiedName, $value)
42
    {
43
        // TODO: Implement setAttributeNS() method.
44
    }
45
46
    public function getAttributeNS($namespaceURI, $localName)
47
    {
48
        // TODO: Implement getAttributeNS() method.
49
    }
50
51 121
    public function appendChild(XMLDocumentInterface $newNode)
52
    {
53 121
        return $this->dom->appendChild($newNode->getElement());
54
    }
55
56 121
    public function createElement($name, $value = null)
57
    {
58
        // on PHP 5.4.* createElement method with null parameter will create empty DOMText object as child of created element
59 121
        $element = $value === null ? $this->dom->createElement($name) : $this->dom->createElement($name, $value);
60
61 121
        return new DOMElementWrapper($element);
62
    }
63
64
    public function createElementNS($namespaceURI, $qualifiedName, $value = null)
65
    {
66
        return $this->dom->createElementNS($namespaceURI, $qualifiedName, $value);
67
    }
68
69 121
    public static function isLoaded()
70
    {
71 121
        return extension_loaded('dom');
72
    }
73
74 42
    public function saveHTML()
75
    {
76 42
        return $this->dom->saveHTML();
77
    }
78
79
    public function getElement()
80
    {
81
        return $this->dom->documentElement;
82
    }
83
84
    /**
85
     * @param $value
86
     */
87
    public function setNodeValue($value)
88
    {
89
        throw NotImplementedException::newInstance();
90
    }
91
92
    public function getNodeValue()
93
    {
94
        throw NotImplementedException::newInstance();
95
    }
96
97
    /**
98
     * @inheritdoc
99
     */
100
    public function removeNode(XMLDocumentInterface $child)
101
    {
102
        return $this->dom->documentElement->removeChild($child->getElement());
103
    }
104
}