ElseAttribute   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 3

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
wmc 2
cbo 3
ccs 9
cts 10
cp 0.9
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A visit() 0 16 2
1
<?php
2
namespace Goetas\Twital\Attribute;
3
4
use Goetas\Twital\Attribute as AttributeBase;
5
use Goetas\Twital\Compiler;
6
use Goetas\Twital\Exception;
7
8
/**
9
 *
10
 * @author Asmir Mustafic <[email protected]>
11
 *
12
 */
13
class ElseAttribute implements AttributeBase
14
{
15 2
    public function visit(\DOMAttr $att, Compiler $context)
16
    {
17 2
        $node = $att->ownerElement;
18
19 2
        if (!$prev = IfAttribute::findPrevElement($node)) {
20
            throw new Exception("The attribute 'elseif' must be the very next sibling of an 'if' of 'elseif' attribute");
21
        }
22
23 2
        $pi = $context->createControlNode("else");
24 2
        $node->parentNode->insertBefore($pi, $node);
25
26 2
        $pi = $context->createControlNode("endif");
27 2
        $node->parentNode->insertBefore($pi, $node->nextSibling);
28
29 2
        $node->removeAttributeNode($att);
30 2
    }
31
}
32