MacroNode::visit()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.004

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 9
cts 10
cp 0.9
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.004
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
9
/**
10
 *
11
 * @author Asmir Mustafic <[email protected]>
12
 *
13
 */
14
class MacroNode implements Node
15
{
16 3
    public function visit(\DOMElement $node, Compiler $context)
17
    {
18 3
        if (!$node->hasAttribute("name")) {
19
            throw new Exception("Name attribute is required");
20
        }
21
22 3
        $context->compileChilds($node);
23
24 3
        $set = iterator_to_array($node->childNodes);
25
26 3
        $start = $context->createControlNode("macro " . $node->getAttribute("name") . "(" . $node->getAttribute("args") . ")");
27 3
        array_unshift($set, $start);
28
29 3
        $set[] = $context->createControlNode("endmacro");
30
31 3
        DOMHelper::replaceWithSet($node, $set);
32 3
    }
33
}
34