Completed
Push — master ( f391ee...a5fa8e )
by James Ekow Abaka
08:36
created

Mustache::generateFromString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace ntentan\honam\template_engines;
4
5
use ntentan\honam\TemplateEngine;
6
7
/**
8
 * Description of Mustache
9
 *
10
 * @author ekow
11
 */
12
class Mustache extends TemplateEngine
13
{
14
    private $mustache;
15
    /**
16
     * 
17
     * @return \Mustache_Engine
18
     */
19
    private function getMustache($loaders = true)
20
    {
21
        if(!is_object($this->mustache) && $loaders == true)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
22
        {
23
            $this->mustache = new \Mustache_Engine([
24
                'loader' => new mustache\MustacheLoader(),
25
                'partials_loader' => new mustache\MustachePartialsLoader($this)
26
            ]);
27
        } elseif (!is_object($this->mustache)) {
28
            $this->mustache = new \Mustache_Engine();
29
        }
30
        return $this->mustache;
31
    }
32
    
33
    protected function generate($data) 
34
    {
35
        $m = $this->getMustache();
36
        return $m->render($this->template, $data);
37
    }
38
    
39
    public function getTemplateFile($name)
40
    {
41
        return self::resolveTemplateFile($name);
42
    }
43
44
    protected function generateFromString($string, $data)
45
    {
46
        $m = $this->getMustache(false);
47
        return $m->render($string, $data);
48
    }
49
50
}
51