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

Evaluate   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 60.71%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 56
ccs 17
cts 28
cp 0.6071
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A eval1() 0 9 1
A eval2() 0 25 3
A __construct() 0 5 1
A eval3() 0 7 1
1
<?php
2
3
namespace Sketch\Tpl\Tag;
4
5
class Evaluate extends Tag
6
{
7 2
    public function __construct()
8
    {
9 2
        $this->eval1();
10 2
        $this->eval2();
11 2
        $this->eval3();
12 2
    }
13
14 2
    private function eval1(): void
15
    {
16 2
        $search = "/{{(\s?)+([\w\.]+)(\s?)+}}/is";
17
18
        Tag::match($search, function($var) {
19
20 2
            $var = str_replace('.', '->', $var);
21
22 2
            Tag::replace("<?= \$$var ?>");
23 2
        });
24 2
    }
25
26 2
    private function eval2(): void
27
    {
28 2
        $search = "/{{(\s?)+([\w\.]+)(\s?)+\|(\s?)+([\w|]+)(\s?)+}}/is";
29
30
        Tag::match($search, function($var, $filter) {
31
32
            $var = str_replace('.', '->', $var);
33
34
            $filters = explode('|', $filter);
35
36
            $res = "<?= ";
37
            
38
            foreach ($filters as $filter) {
0 ignored issues
show
introduced by
$filter is overwriting one of the parameters of this function.
Loading history...
39
                $res .= "$filter(";
40
            }
41
42
            $res .= "$$var";
43
44
            foreach ($filters as $filter) {
0 ignored issues
show
introduced by
$filter is overwriting one of the parameters of this function.
Loading history...
45
                $res .= ")";
46
            }
47
48
            $res .= " ?>";
49
50
            Tag::replace($res);
51 2
        });
52 2
    }
53
54 2
    private function eval3(): void
55
    {
56 2
        $search = "/{{(\s?)+([\w]+)(\s?)+\((.*?)\)(\s?)+}}/is";
57
58
        Tag::match($search, function($func, $params) {
59
60
            Tag::replace("<?= $func($params) ?>");
61 2
        });
62 2
    }
63
}
64