Completed
Pull Request — master (#4)
by James Ekow Abaka
03:06 queued 36s
created

SmartyEngine   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 34
ccs 6
cts 9
cp 0.6667
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A renderFromFileTemplate() 0 4 1
A __construct() 0 3 1
A renderFromStringTemplate() 0 4 1
1
<?php
2
3
namespace ntentan\honam\engines;
4
5
6
use ntentan\honam\engines\smarty\Core;
7
8
/**
9
 * Description of Mustache
10
 *
11
 * @author ekow
12
 */
13
class SmartyEngine extends AbstractEngine
14
{
15
    private $smarty;
16
17 1
    public function __construct(Core $smarty)
18
    {
19 1
        $this->smarty = $smarty;
20 1
    }
21
22
    /**
23
     * Passes the data to be rendered to the template engine instance.
24
     * @param string $filePath
25
     * @param array $data
26
     * @return string
27
     * @throws \SmartyException
28
     */
29 1
    public function renderFromFileTemplate(string $filePath, array $data): string
30
    {
31 1
        $this->smarty->setData($data);
32 1
        return $this->smarty->fetch($filePath);
33
    }
34
35
    /**
36
     * Passes a template string and data to be rendered to the template engine
37
     * instance.
38
     * @param string $string
39
     * @param array $data
40
     * @return string
41
     * @throws \SmartyException
42
     */
43
    public function renderFromStringTemplate(string $string, array $data): string
44
    {
45
        $this->smarty->setData($data);
46
        return $this->smarty->fetch("string:$string");
47
    }
48
}
49