ElseAttribute::visit()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.004

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 10
cp 0.9
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.004
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