ElseIfAttribute   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 3

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
wmc 5
cbo 3
ccs 12
cts 13
cp 0.9231
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A visit() 0 20 5
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
use Goetas\Twital\Twital;
8
9
/**
10
 *
11
 * @author Asmir Mustafic <[email protected]>
12
 *
13
 */
14
class ElseIfAttribute implements AttributeBase
15
{
16 4
    public function visit(\DOMAttr $att, Compiler $context)
17
    {
18 4
        $node = $att->ownerElement;
19
20 4
        if (!$prev = IfAttribute::findPrevElement($node)) {
21
            throw new Exception("The attribute 'elseif' must be the very next sibling of an 'if' of 'elseif' attribute");
22
        }
23
24 4
        $pi = $context->createControlNode("elseif " . html_entity_decode($att->value));
25 4
        $node->parentNode->insertBefore($pi, $node);
26
27 4
        if (!($nextElement = IfAttribute::findNextElement($node)) || (!$nextElement->hasAttributeNS(Twital::NS, 'elseif') && !$nextElement->hasAttributeNS(Twital::NS, 'else'))) {
28 3
            $pi = $context->createControlNode("endif");
29 3
            $node->parentNode->insertBefore($pi, $node->nextSibling); // insert after
30 3
        } else {
31 2
            IfAttribute::removeWhitespace($node);
32
        }
33
34 4
        $node->removeAttributeNode($att);
35 4
    }
36
}
37