BasicTemplate   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 85.29%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 80
ccs 29
cts 34
cp 0.8529
rs 10
wmc 12
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
B buildScript() 0 13 6
A render() 0 23 3
A setParent() 0 4 1
A getContentParent() 0 4 1
A setContentParent() 0 4 1
1
<?php
2
namespace JayaCode\Framework\Core\View\Template;
3
4
/**
5
 * Class BasicTemplate
6
 * @package JayaCode\Framework\Core\View\Template
7
 */
8
class BasicTemplate extends Template
9
{
10
    /**
11
     * @var
12
     */
13
    protected $parent;
14
15
    /**
16
     * @return string
17
     */
18 3
    public function buildScript()
19
    {
20 3
        $fileCache = $this->cacheDir.str_replace(["/", "."], "_", $this->fileTemplate);
21 3
        if ($this->cacheDir !== null && file_exists($fileCache) && empty($this->contentParent)) {
22
            return $this->script = file_get_contents($fileCache);
23
        }
24
25 3
        $this->script = $this->converter->build(file_get_contents($this->locTemplate));
26
27 3
        if ($this->cacheDir !== null && empty($this->contentParent)) {
28
            file_put_contents($fileCache, $this->script);
29
        }
30 3
    }
31
32
    /**
33
     * @return mixed|string
34
     */
35 3
    public function render()
36
    {
37 3
        if ($this->script === null) {
38 3
            $this->buildScript();
39 3
        }
40
41 3
        $varArray = $this->vars->all();
42 3
        extract($varArray);
43
        
44 3
        ob_start();
45 3
        eval("?>" . $this->script);
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
46 3
        $result = ob_get_contents();
47 3
        ob_end_clean();
48
        
49 3
        if ($this->parent) {
50 3
            $fileParent = str_replace(".", "/", $this->parent);
51 3
            $fileParent = $fileParent.Template::$extension;
52 3
            $parent = new BasicTemplate($this->locView, $fileParent, $this->variableCollector, $this->converter);
53 3
            $parent->setContentParent($this->contentParent);
54 3
            return $parent->render();
55
        }
56 3
        return $result;
57
    }
58
59
    /**
60
     * @param $name
61
     */
62 3
    public function setParent($name)
63
    {
64 3
        $this->parent = $name;
65 3
    }
66
67
    /**
68
     * @var array
69
     */
70
    protected $contentParent = [];
71
72
    /**
73
     * @return array
74
     */
75
    public function getContentParent()
76
    {
77
        return $this->contentParent;
78
    }
79
80
    /**
81
     * @param array $contentParent
82
     */
83 3
    public function setContentParent($contentParent)
84
    {
85 3
        $this->contentParent = $contentParent;
86 3
    }
87
}
88