Completed
Push — master ( 069124...27e495 )
by Edson
02:00
created

Condition   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 46.88%

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 58
ccs 15
cts 32
cp 0.4688
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A elseif() 0 15 1
A else() 0 12 1
A if() 0 16 1
A __construct() 0 5 1
1
<?php
2
3
namespace Sketch\Tpl\Tag;
4
5
class Condition extends Tag
6
{
7 2
    public function __construct()
8
    {
9 2
        $this->elseif();
10 2
        $this->else();
11 2
        $this->if();
12 2
    }
13
14 2
    private function if()
15
    {
16 2
        $search = "/{(\s?)+if(\s?)+([\$\w\.]+)(\s?)+([<>!=]+)(\s?)+([\$\w\d\.\"' ]+)(\s?)+}(.*?){(\s?)+\/if(\s?)+}/is";
17
18
        Tag::match($search, function($left, $op, $right, $content = "") {
19
            
20
            $left  = str_replace('.', '->', $left);
21
            $right = str_replace('.', '->', $right);
22
23
            $res  = "<?php if ($left $op $right) { ?>";
24
            $res .= $content;
25
            $res .= "<?php } ?>";
26
            
27
            Tag::replace($res);
28
29
            $this->if();
30 2
        });
31 2
    }
32
33 2
    private function else()
34
    {
35 2
        $search = "/{(\s?)+else(\s?)+}(.*?)/is";
36
37
        Tag::match($search, function($content = "") {
38
39
            $res  = "<?php } else { ?>";
40
            $res .= $content;
41
42
            Tag::replace($res);
43
44
            $this->else();
45 2
        });
46 2
    }
47
48 2
    private function elseif()
49
    {
50 2
        $search = "/{(\s?)+elseif(\s?)+([\$\w\.]+)(\s?)+([<>!=]+)(\s?)+([\$\w\d\.\"' ]+)(\s?)+}(.*?)/is";
51
52
        Tag::match($search, function($left, $op, $right, $content = "") {
53
            
54
            $left  = str_replace('.', '->', $left);
55
            $right = str_replace('.', '->', $right);
56
57
            $res  = "<?php } elseif ($left $op $right) { ?>";
58
            $res .= $content;
59
60
            Tag::replace($res);
61
62
            $this->elseif();
63 2
        });
64 2
    }
65
}
66