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

Mustache   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 1
cbo 4
dl 0
loc 39
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMustache() 0 13 4
A generate() 0 5 1
A getTemplateFile() 0 4 1
A generateFromString() 0 5 1
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