DomDocument::loadString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 1
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