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

Evaluate::eval2()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 8.2077

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 1
nop 0
dl 0
loc 25
ccs 2
cts 12
cp 0.1666
crap 8.2077
rs 9.8666
c 0
b 0
f 0
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