Printer::import()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 0
cts 11
cp 0
rs 9.4285
cc 3
eloc 7
nc 3
nop 3
crap 12
1
<?php
2
3
namespace tomzx\HtmlParser;
4
5
use DOMDocument;
6
use DOMNode;
7
8
class Printer
9
{
10
    public function output(array $statements)
11
    {
12
        $document = new \DOMDocument();
13
        $document->formatOutput = true;
14
15
        $this->import($document, $document, $statements);
16
17
        echo $document->saveHTML();
18
    }
19
20
    protected function import(DOMDocument $document, DomNode $node, array $statements)
21
    {
22
        /** @var Node $statement */
23
        foreach ($statements as $statement) {
24
            $newNode = $statement->getNode()->cloneNode(false);
25
26
            $newNode = $document->importNode($newNode);
27
            $newNode = $node->appendChild($newNode);
28
            if ($statement->hasChildren()) {
29
                $this->import($document, $newNode, $statement->getChildren());
30
            }
31
        }
32
    }
33
}
34