Template   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 8
c 2
b 0
f 1
dl 0
loc 28
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 15 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas;
6
7
use Canvas\Models\EmailTemplates;
8
use Phalcon\Di;
9
10
/**
11
 * Class Validation.
12
 *
13
 * @package Canvas
14
 */
15
class Template
16
{
17
    /**
18
     * Given the email tempalte name and its params
19
     *  - create the files
20
     *  - render it with the variables
21
     *  - return the content string for use to use anywhere.
22
     *
23
     * @param string $name
24
     * @param array $params
25
     *
26
     * @return string
27
     */
28
    public static function generate(string $name, array $params) : string
29
    {
30
        $di = Di::getDefault();
31
        $view = $di->getView();
32
        $filesystem = $di->get('filesystem', ['local']);
33
34
        //get the teamplate
35
        $template = EmailTemplates::getByName($name);
36
        $file = $template->name . '.volt';
37
38
        //write file
39
        $filesystem->put('/view/' . $file, $template->template);
40
41
        //rendre and return content
42
        return $view->render($template->name, $params);
43
    }
44
}
45