Printer::output()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.6666
cc 1
eloc 5
nc 1
nop 1
crap 2
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