BlockInnerAttribute   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
cbo 2
dl 0
loc 30
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A visit() 0 27 2
1
<?php
2
namespace Goetas\Twital\Attribute;
3
4
use Goetas\Twital\Attribute as AttributeBase;
5
use Goetas\Twital\Compiler;
6
use Goetas\Twital\Helper\DOMHelper;
7
use Goetas\Twital\Twital;
8
9
/**
10
 * This will translate '<div t:block-inner="name">foo</div>' into '<div>{% block name%}foo{% endblock %}</div>'
11
 * @author Asmir Mustafic <[email protected]>
12
 *
13
 */
14
class BlockInnerAttribute implements AttributeBase
15
{
16 15
    public function visit(\DOMAttr $att, Compiler $context)
17
    {
18 15
        $node = $att->ownerElement;
19 15
        $node->removeAttributeNode($att);
20
21
        // create sandbox and append it to the node
22 15
        $sandbox = $node->ownerDocument->createElementNS(Twital::NS, "sandbox");
23
24
        // move all child to sandbox to sandbox
25 15
        while ($node->firstChild) {
26 15
            $child = $node->removeChild($node->firstChild);
27 15
            $sandbox->appendChild($child);
28 15
        }
29 15
        $node->appendChild($sandbox);
30
31
        //$context->compileAttributes($node);
32 15
        $context->compileChilds($sandbox);
33
34
35 15
        $start = $context->createControlNode("block " . $att->value);
36 15
        $end = $context->createControlNode("endblock");
37
38 15
        $sandbox->insertBefore($start, $sandbox->firstChild);
39 15
        $sandbox->appendChild($end);
40
41 15
        DOMHelper::replaceWithSet($sandbox, iterator_to_array($sandbox->childNodes));
42 15
    }
43
}
44