BlockOuterAttribute   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 2

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A visit() 0 25 1
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-outer="name">foo</div>' into '{% block name%}<div>foo</div>{% endblock %}'
11
 *
12
 * @author Asmir Mustafic <[email protected]>
13
 *
14
 */
15
class BlockOuterAttribute implements AttributeBase
16
{
17 6
    public function visit(\DOMAttr $att, Compiler $context)
18
    {
19 6
        $node = $att->ownerElement;
20 6
        $node->removeAttributeNode($att);
21
22
        // create sandbox
23 6
        $sandbox = $node->ownerDocument->createElementNS(Twital::NS, "sandbox");
24 6
        $node->parentNode->insertBefore($sandbox, $node);
25
26
        // move to sandbox
27 6
        $node->parentNode->removeChild($node);
28 6
        $sandbox->appendChild($node);
29
30 6
        $context->compileAttributes($node);
31 6
        $context->compileChilds($node);
32
33
34 6
        $start = $context->createControlNode("block " . $att->value);
35 6
        $end = $context->createControlNode("endblock");
36
37 6
        $sandbox->insertBefore($start, $sandbox->firstChild);
38 6
        $sandbox->appendChild($end);
39
40 6
        DOMHelper::replaceWithSet($sandbox, iterator_to_array($sandbox->childNodes));
41 6
    }
42
}
43