UseNode::visit()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0052

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 11
cts 12
cp 0.9167
rs 9.7
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3.0052
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 UseNode implements Node
14
{
15 9
    public function visit(\DOMElement $node, Compiler $context)
16
    {
17 9
        $code = "use ";
18
19 9
        if ($node->hasAttribute("from")) {
20 9
            $code .= '"' . $node->getAttribute("from") . '"';
21 9
        } else {
22
            throw new Exception("The 'from' attribute is required");
23
        }
24
25 9
        if ($node->hasAttribute("with")) {
26 3
            $code .= " with " . $node->getAttribute("with");
27 3
        }
28
29 9
        $pi = $context->createControlNode($code);
30 9
        $node->parentNode->replaceChild($pi, $node);
31 9
    }
32
}
33