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

Tag::match()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sketch\Tpl\Tag;
4
5
abstract class Tag
6
{
7
    protected static $blocks = [];
8
    protected static $config;
9
    
10
    private static $content;
11
12
    private $search;
13
14 2
    protected function replace(string $replace): void
15
    {
16 2
        self::$content = str_replace($this->search, $replace, self::$content);
17 2
    }
18
19 2
    protected function match($pattern, $callback): void
20
    {
21 2
        if (preg_match_all($pattern, self::getContent(), $matches, PREG_SET_ORDER)) {
22 2
            foreach ($matches as $match) {
23
                
24 2
                $this->search = $match[0];
25
26 2
                unset($match[0]);
27
28 2
                call_user_func_array($callback, array_filter($match));
29
            }
30
        }
31 2
    }
32
33 2
    public static function setContent(string $content): void
34
    {
35 2
        self::$content = $content;
36 2
    }
37
38 2
    public static function getContent(): string
39
    {
40 2
        return self::$content;
41
    }
42
43 2
    public static function setConfig(array $config): void
44
    {
45 2
        self::$config = $config;
46 2
    }
47
48 2
    public static function getConfig(): array
49
    {
50 2
        return self::$config;
51
    }
52
}
53