Passed
Pull Request — develop (#10)
by Brent
04:23 queued 01:29
created

SmartyEngine   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 2
dl 0
loc 50
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A renderTemplate() 0 3 1
A addTemplateVariables() 0 7 2
A clearTemplateVariables() 0 5 1
A addTemplateVariable() 0 5 1
A hasTemplateVariable() 0 3 1
A clearTemplateVariable() 0 5 1
A getTemplateExtensions() 0 3 1
1
<?php
2
3
namespace Brendt\Stitcher\Template\Smarty;
4
5
use \Smarty;
6
use Brendt\Stitcher\Template\TemplateEngine;
7
use Symfony\Component\Finder\SplFileInfo;
8
9
/**
10
 * The Smarty template engine.
11
 */
12
class SmartyEngine extends Smarty implements TemplateEngine
13
{
14
    public function __construct($templateDir = './src', $cacheDir = './.cache') {
15
        parent::__construct();
16
17
        $this->addTemplateDir($templateDir);
18
        $this->setCompileDir($cacheDir);
19
        $this->addPluginsDir([__DIR__]);
20
21
        $this->caching = false;
22
    }
23
24
    public function renderTemplate(SplFileInfo $template) {
25
        return $this->fetch($template->getRealPath());
26
    }
27
28
    public function addTemplateVariables(array $variables) {
29
        foreach ($variables as $name => $variable) {
30
            $this->assign($name, $variable);
31
        }
32
33
        return $this;
34
    }
35
36
    public function clearTemplateVariables() {
37
        $this->clearAllAssign();
38
39
        return $this;
40
    }
41
42
    public function addTemplateVariable($name, $value) {
43
        $this->assign($name, $value);
44
45
        return $this;
46
    }
47
48
    public function hasTemplateVariable(string $name) : bool {
49
        return $this->getTemplateVars($name) != null;
50
    }
51
52
    public function clearTemplateVariable($variable) {
53
        $this->clearAssign($variable);
54
55
        return $this;
56
    }
57
58
    public function getTemplateExtensions(): array {
59
        return ['tpl'];
60
    }
61
}
62