ExtendsNode   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 3

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
dl 0
loc 26
c 0
b 0
f 0
wmc 4
cbo 3
ccs 16
cts 17
cp 0.9412
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A visit() 0 23 4
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 ExtendsNode implements Node
15
{
16 24
    public function visit(\DOMElement $node, Compiler $context)
17
    {
18 24
        if ($node->hasAttribute("from-exp")) {
19 3
            $filename = $node->getAttribute("from-exp");
20 24
        } elseif ($node->hasAttribute("from")) {
21 21
            $filename = '"' . $node->getAttribute("from") . '"';
22 21
        } else {
23
            throw new Exception("The 'from' or 'from-exp' attribute is required");
24
        }
25
26 24
        $context->compileChilds($node);
27
28 24
        $ext = $context->createControlNode("extends {$filename}");
29
30 24
        $set = iterator_to_array($node->childNodes);
31 24
        if (count($set)) {
32 18
            $n = $node->ownerDocument->createTextNode("\n");
33 18
            array_unshift($set, $n);
34 18
        }
35 24
        array_unshift($set, $ext);
36
37 24
        DOMHelper::replaceWithSet($node, $set);
38 24
    }
39
}
40