Passed
Push — master ( ab7df5...238a89 )
by Edson
01:47
created

FuncTpl   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 40
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setFuncName() 0 3 1
A func() 0 9 3
A __construct() 0 4 1
A __toString() 0 3 1
A setFuncArgs() 0 3 1
1
<?php
2
3
namespace Bonfim\Component\View;
4
5
class FuncTpl
6
{
7
    private $pattern = '/{\s?func ([\w]+)\((.*?)\)\s?}/is';
8
    private $content;
9
    private $match;
10
    private $funcName;
11
    private $funcArgs;
12
13
    public function __construct(string $content)
14
    {
15
        $this->content = $content;
16
        $this->func();
17
    }
18
19
    public function __toString(): string
20
    {
21
        return $this->content;
22
    }
23
24
    public function func(): void
25
    {
26
        if (preg_match_all($this->pattern, $this->content, $matches, PREG_SET_ORDER)) {
27
            for ($i = 0; $i < count($matches); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
28
                $this->match = $matches[$i];
29
                $this->setFuncName();
30
                $this->setFuncArgs();
31
                $content = '<?php echo('.$this->funcName.'('.$this->funcArgs.')); ?>';
32
                $this->content = str_replace($matches[$i][0], $content, $this->content);
33
            };
34
        }
35
    }
36
37
    private function setFuncName()
38
    {
39
        $this->funcName = $this->match[1];
40
    }
41
42
    private function setFuncArgs()
43
    {
44
        $this->funcArgs = $this->match[2];
45
    }
46
}
47