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

Tag   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 68
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A replace() 0 3 1
A __construct() 0 7 3
A setConfig() 0 3 1
A getContent() 0 3 1
A setContent() 0 3 1
A getConfig() 0 3 1
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