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

SmartyEngine::renderFromFileTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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