IncludeNode   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 2

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
dl 0
loc 31
c 0
b 0
f 0
wmc 10
cbo 2
ccs 22
cts 23
cp 0.9565
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B visit() 0 28 10
1
<?php
2
namespace Goetas\Twital\Node;
3
4
use Goetas\Twital\Compiler;
5
use Goetas\Twital\Exception;
6
use Goetas\Twital\Node;
7
8
/**
9
 *
10
 * @author Asmir Mustafic <[email protected]>
11
 *
12
 */
13
class IncludeNode implements Node
14
{
15 21
    public function visit(\DOMElement $node, Compiler $context)
16
    {
17 21
        $code = "include ";
18
19 21
        if ($node->hasAttribute("from-exp")) {
20 3
            $code .= $node->getAttribute("from-exp");
21 21
        } elseif ($node->hasAttribute("from")) {
22 18
            $code .= '"' . $node->getAttribute("from") . '"';
23 18
        } else {
24
            throw new Exception("The 'from' or 'from-exp' attribute is required");
25
        }
26
27 21
        if ($node->hasAttribute("ignore-missing") && $node->getAttribute("ignore-missing") !== "false") {
28 3
            $code .= " ignore missing";
29 3
        }
30 21
        if ($node->hasAttribute("with")) {
31 9
            $code .= " with " . $node->getAttribute("with");
32 9
        }
33 21
        if ($node->hasAttribute("only") && $node->getAttribute("only") !== "false") {
34 3
            $code .= " only";
35 3
        }
36 21
        if ($node->hasAttribute("sandboxed") && $node->getAttribute("sandboxed") !== "false") {
37 3
            $code .= " sandboxed = true";
38 3
        }
39
40 21
        $pi = $context->createControlNode($code);
41 21
        $node->parentNode->replaceChild($pi, $node);
42 21
    }
43
}
44