Tag::replace()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
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