Printer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 26
ccs 0
cts 18
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A output() 0 9 1
A import() 0 13 3
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