Inheritance::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bonfim\Tpl\Tag;
4
5
class Inheritance extends Tag
6
{
7
    public function __construct()
8
    {
9
        $this->getBlockContent();
10
        $this->getParentContent();
11
    }
12
13
    private function getBlockContent(): void
14
    {
15
        $search = "/@(\s?)+extends.*@(\s?)+block(\s?)+([\w]+)/is";
16
17
        Tag::match($search, function($blockName) {
18
19
            $search = "/@(\s?)+block(\s?)+$blockName(.*?)@(\s?)+endblock/is";
20
21
            Tag::match($search, function($content) use ($blockName) {
22
23
                if (!array_key_exists($blockName, Tag::$blocks)) {
24
                    Tag::$blocks[$blockName] = $content;
25
                }
26
27
                Tag::replace('');
28
29
                $this->getBlockContent();
30
            });
31
        });
32
    }
33
34
    private function getParentContent(): void
35
    {
36
        $search = "/@(\s?)+extends ([\w\.]+)/is";
37
38
        Tag::match($search, function($layoutName) {
39
40
            $layoutName = str_replace('.', '/', $layoutName);
41
42
            $content = \Bonfim\Tpl\Content::getContent($layoutName);
43
          
44
            Tag::replace($content);
45
            
46
            $this->__construct();
47
        });
48
    }
49
}
50