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

Inheritance::getBlockContent()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3.4578

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 1
nop 0
dl 0
loc 17
ccs 2
cts 7
cp 0.2857
crap 3.4578
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sketch\Tpl\Tag;
4
5
class Inheritance extends Tag
6
{
7 2
    public function __construct()
8
    {
9 2
        $this->getBlockContent();
10 2
        $this->getParentContent();
11 2
    }
12
13 2
    private function getBlockContent(): void
14
    {
15 2
        $search = "/{(\s?)+extends.*}.*{(\s?)+([\w]+)(\s?)+}/is";
16
17
        Tag::match($search, function($blockName) {
18
19
            $search = "/{(\s?)+$blockName(\s?)+}(.*?){(\s?)+\/$blockName(\s?)+}/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 2
        });
32 2
    }
33
34 2
    private function getParentContent(): void
35
    {
36 2
        $search = "/{(\s?)+extends ['\"]([\w\.]+)['\"](\s?)+}/is";
37
38
        Tag::match($search, function($layoutName) {
39
40
            $layoutName = str_replace('.', '/', $layoutName);
41
42
            $content = \Sketch\Tpl\Content::getContent($layoutName, Tag::$config);
43
          
44
            Tag::replace($content);
45
            
46
            $this->__construct();
47 2
        });
48 2
    }
49
}
50