Completed
Push — master ( 8d3e79...9daf84 )
by Edson
04:12
created

Engine::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 17
ccs 10
cts 10
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Bonfim\Tpl;
4
5
class Engine extends Content
6
{
7
    private $config;
8
    private $data = ['__version' => '1.1.0'];
9
10 2
    public function config(array $config): void
11
    {
12 2
        $this->config = $config;
13 2
    }
14
15 2
    public function render(string $view, array $data = []): string
16
    {
17 2
        $content = $this->handle($this->getContent($view, $this->config));
18
19 2
        $this->data = array_merge($data, $this->data);
20
21 2
        $fname = getcwd() . '/' . $this->config['cache_dir'] . '/' . $view . '.phtml';
22
23 2
        $file = new File;
24
25 2
        if ($file->create($fname) !== false) {
26 2
            $file->write($content);
27 2
            $content = $file->read($this->data);
28 2
            $file->close();
29
        }
30
31 2
        return $content;
32
    }
33
34 2
    private function handle($content)
35
    {
36 2
        $content = new Inheritance($content, $this->config);
37 2
        $content = new IncludeTpl($content, $this->config);
38 2
        $content = new ForeachTpl($content);
39 2
        $content = new IfTpl($content);
40 2
        $content = new FuncTpl($content);
41 2
        $content = new VariableTpl($content);
42
43 2
        return $content;
44
    }
45
}
46