BlockNode   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 3

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
dl 0
loc 26
c 0
b 0
f 0
wmc 2
cbo 3
ccs 15
cts 16
cp 0.9375
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A visit() 0 23 2
1
<?php
2
namespace Goetas\Twital\Node;
3
4
use Goetas\Twital\Compiler;
5
use Goetas\Twital\Exception;
6
use Goetas\Twital\Helper\DOMHelper;
7
use Goetas\Twital\Node;
8
use Goetas\Twital\Twital;
9
10
/**
11
 *
12
 * @author Asmir Mustafic <[email protected]>
13
 *
14
 */
15
class BlockNode implements Node
16
{
17 21
    public function visit(\DOMElement $node, Compiler $context)
18
    {
19 21
        if (!$node->hasAttribute("name")) {
20
            throw new Exception("Name attribute is required");
21
        }
22
23 21
        $sandbox = $node->ownerDocument->createElementNS(Twital::NS, "sandbox");
24 21
        $node->parentNode->insertBefore($sandbox, $node);
25 21
        $node->parentNode->removeChild($node);
26 21
        $sandbox->appendChild($node);
27
28 21
        $context->compileAttributes($node);
29 21
        $context->compileChilds($node);
30
31 21
        $start = $context->createControlNode("block " . $node->getAttribute("name"));
32 21
        $end = $context->createControlNode("endblock");
33
34 21
        $sandbox->insertBefore($start, $sandbox->firstChild);
35 21
        $sandbox->appendChild($end);
36
37 21
        DOMHelper::replaceWithSet($sandbox, iterator_to_array($sandbox->childNodes));
38 21
        DOMHelper::replaceWithSet($node, iterator_to_array($node->childNodes));
39 21
    }
40
}
41