Passed
Push — master ( ab7df5...238a89 )
by Edson
01:47
created

ParseTpl::setContent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Bonfim\Component\View;
4
5
trait ParseTpl
6
{
7
    protected $config = array();
8
    protected $data = array(
9
        '__version' => '1.0.0'
10
    );
11
    protected $view = '';
12
13
    public function config(array $config)
14
    {
15
        $this->config = $config;
16
    }
17
18
    public function getContent($view): string
19
    {
20
        $file = getcwd() . '/' . $this->config['template_dir'] . "/$view.html";
21
22
        if (!file_exists($file)) {
23
            throw new \Exception("$file template not found");
24
        }
25
26
        return $this->removeTags(file_get_contents($file));
27
    }
28
29
    public function removeTags($content)
30
    {
31
        return str_replace(array("<?", "?>"), array("&lt;?", "?&gt;"), $content);
32
    }
33
}
34