DomDocument   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 22
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A loadString() 0 10 1
A loadDOM() 0 8 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