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

DOMWrapper::setAttributeNS()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 3
crap 2
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
}