BasicConvert::build()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.1481

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 10
ccs 4
cts 6
cp 0.6667
crap 2.1481
rs 9.4285
1
<?php
2
namespace JayaCode\Framework\Core\View\Converter;
3
4
class BasicConvert implements Converter
5
{
6
    protected $content;
7
8
    protected $options = [
9
        "preg_replace" => [
10
            [
11
                '/{{/',
12
                '/}}/',
13
                '/\[\[/',
14
                '/\]\]/',
15
                '/^\s*@(.*)$/m',
16
                '/^\s*\[@\s*parent\s*([\w|\.]*)\s*@\]\s*$/m',
17
                '/\s*\[@\s*content\s*(\w*)\s*@\](.*)\[@\s*endcontent\s*@\]/Usm'
18
            ],
19
            [
20
                '<?php echo(htmlspecialchars(',
21
22
                ")); ?>",
23
24
                '<?php ',
25
26
                " ?>",
27
28
                "<?php \\1 ?>",
29
30
                "<?php \$this->setParent('\\1'); ?>",
31
32
                " <?php if (array_key_exists('\\1', \$this->contentParent)) {
33
                    print(\$this->contentParent['\\1']);
34
                } elseif (!\$this->parent) { ?>
35
                    \\2
36
                <?php } else { ?>
37
                    <?php ob_start(); ?> \\2 <?php \$this->contentParent['\\1'] = ob_get_contents(); ob_end_clean(); ?>
38
                <?php } ?>"
39
            ]
40
        ],
41
    ];
42
43
    public function setContent($content)
44
    {
45
        $this->content = $content;
46
    }
47
48 15
    public function build($content = null, $options = array())
49
    {
50 15
        $this->options = $options + $this->options;
51
52 15
        if (!is_null($this->content)) {
53
            $content = $this->content;
54
        }
55
56 15
        return preg_replace($this->options['preg_replace'][0], $this->options['preg_replace'][1], $content);
57
    }
58
}
59