IncludeNode::visit()   B
last analyzed

Complexity

Conditions 10
Paths 33

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 10.0082

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 22
cts 23
cp 0.9565
rs 7.6666
c 0
b 0
f 0
cc 10
nc 33
nop 2
crap 10.0082

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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