Passed
Push — master ( 973a91...34c593 )
by Edson
01:12
created

Tag::getContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sketch\Tpl;
4
5
/**
6
 * Class Tag
7
 * @package Sketch\Tpl
8
 */
9
abstract class Tag
10
{
11
    /**
12
     * @var
13
     */
14
    protected static $content;
15
    
16
    /**
17
     * @var
18
     */
19
    protected static $config;
20
21
    protected $match = [];
22
23 22
    /**
24
     * Tag constructor.
25 22
     */
26 22
    public function __construct(string $pattern)
27
    {
28
        if (preg_match_all($pattern, self::getContent(), $matches, PREG_SET_ORDER)) {
29
            $count = count($matches);
30
            for ($i = 0; $i < $count; $i++) {
31
                $this->match = $matches[$i];
32
                $this->replace($this->handle());
33
            }
34
        }
35
    }
36 22
37
    /**
38 22
     * @return mixed
39 22
     */
40
    abstract public function handle(): string;
41
42
    protected function replace(string $replace): void
43
    {
44 22
        self::setContent(str_replace($this->match[0], $replace, self::getContent()));
45
    }
46 22
47
    /**
48
     * @param string $content
49
     */
50
    public static function setContent(string $content): void
51
    {
52 6
        self::$content = $content;
53
    }
54 6
55 6
    /**
56
     * @return string
57
     */
58
    public static function getContent(): string
59
    {
60 2
        return self::$content;
61
    }
62 2
63
    /**
64
     * @param array $config
65
     */
66
    public static function setConfig(array $config): void
67
    {
68
        self::$config = $config;
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    public static function getConfig(): array
75
    {
76
        return self::$config;
77
    }
78
}
79