DomDocument::loadDOM()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rs\XmlFilter\Document;
6
7
use Webmozart\Assert\Assert;
8
9
class DomDocument extends BaseDocument implements Document
10
{
11 11
    public function loadString(string $doc) : Element
12
    {
13 11
        $document = new \DOMDocument();
14 11
        $document->registerNodeClass(\DOMElement::class, DomElement::class);
15 11
        $loaded = $document->loadXML($doc);
16
17 11
        Assert::true($loaded, sprintf('Unable to load the xml string "%s"', $doc));
18
19 11
        return $document->childNodes->item(0);
20
    }
21
22 2
    public function loadDOM(\DOMNode $dom) : Element
23
    {
24 2
        if ($dom instanceof \DOMDocument) {
25 1
            return $this->loadString($dom->saveXML());
26
        }
27
28 1
        return $this->loadString($dom->textContent);
29
    }
30
}
31