Tag::match()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 10
ccs 0
cts 6
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bonfim\Tpl\Tag;
4
5
abstract class Tag
6
{
7
    protected static $blocks = [];
8
    
9
    private static $content;
10
11
    private $search;
12
13
    protected function replace(string $replace): void
14
    {
15
        self::$content = str_replace($this->search, $replace, self::$content);
16
    }
17
18
    protected function match($pattern, $callback): void
19
    {
20
        if (preg_match_all($pattern, self::getContent(), $matches, PREG_SET_ORDER)) {
21
            foreach ($matches as $match) {
22
                
23
                $this->search = $match[0];
24
25
                unset($match[0]);
26
27
                call_user_func_array($callback, array_filter($match));
28
            }
29
        }
30
    }
31
32
    public static function setContent(string $content): void
33
    {
34
        self::$content = $content;
35
    }
36
37
    public static function getContent(): string
38
    {
39
        return self::$content;
40
    }
41
42
    public static function setConfig(array $config): void
43
    {
44
        self::$config = $config;
0 ignored issues
show
Bug Best Practice introduced by
The property config does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
45
    }
46
}
47