OmitAttribute   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 88%

Importance

Changes 0
Metric Value
dl 0
loc 41
c 0
b 0
f 0
wmc 6
cbo 1
ccs 22
cts 25
cp 0.88
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B visit() 0 38 6
1
<?php
2
namespace Goetas\Twital\Attribute;
3
4
use Goetas\Twital\Attribute;
5
use Goetas\Twital\Compiler;
6
7
/**
8
 *
9
 * @author Asmir Mustafic <[email protected]>
10
 *
11
 */
12
class OmitAttribute implements Attribute
13
{
14 5
    public function visit(\DOMAttr $att, Compiler $context)
15
    {
16 5
        $node = $att->ownerElement;
17
18 5
        $pi = $context->createControlNode("set __tmp_omit = " . html_entity_decode($att->value));
19 5
        $node->parentNode->insertBefore($pi, $node);
20
21 5
        $pi = $context->createControlNode("if not __tmp_omit");
22 5
        $node->parentNode->insertBefore($pi, $node);
23
24 5
        $pi = $context->createControlNode("endif");
25 5
        if ($node->firstChild) {
26 5
            $node->insertBefore($pi, $node->firstChild);
27 5
        } else {
28
            $node->appendChild($pi);
29
        }
30
31 5
        $pi = $context->createControlNode("if not __tmp_omit");
32 5
        $node->appendChild($pi);
33
34 5
        $pi = $context->createControlNode("endif");
35
36 5
        if ($node->parentNode->nextSibling) {
37
            $node->parentNode->insertBefore($pi, $node->parentNode->nextSibling);
38
        } else {
39 5
            $node->parentNode->appendChild($pi);
40
        }
41
42 5
        $node->removeAttributeNode($att);
43
44 5
        if ($att->value == "true" || $att->value == "1") {
45 2
            foreach (iterator_to_array($node->attributes) as $att) {
46 2
                $node->removeAttributeNode($att);
47 2
            }
48 2
        }
49
50 5
        return Attribute::STOP_ATTRIBUTE;
51
    }
52
}
53