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

Engine   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A config() 0 3 1
A handle() 0 10 1
A render() 0 17 2
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