Dom::render()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Bmatovu\Ussd\Support;
4
5
class Dom
6
{
7 1
    public static function render(\DOMNode $node): string
8
    {
9 1
        $attrs = '';
10
11 1
        foreach ($node->attributes as $attr) {
12 1
            $attrs .= " {$attr->name}=\"{$attr->value}\"";
13
        }
14
15 1
        return "<{$node->tagName}{$attrs}/>";
16
    }
17
18 11
    public static function getElements(\DOMNodeList $nodeList, ?string $nodeName): array
19
    {
20 11
        $els = array_filter(iterator_to_array($nodeList), static function ($node) use ($nodeName) {
21 11
            if (! $node instanceof \DOMElement) {
22 10
                return false;
23
            }
24
25 11
            if (! $nodeName) {
26 4
                return true;
27
            }
28
29 7
            return $node->nodeName === $nodeName;
30 11
        });
31
32 11
        return array_values($els);
33
    }
34
}
35