Test Setup Failed
Pull Request — master (#216)
by Maximo
04:19
created

Template   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 1
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas;
6
7
use Canvas\Models\EmailTemplates;
8
use Phalcon\Di;
9
use Phalcon\Di\Injectable;
10
11
/**
12
 * Class Validation.
13
 *
14
 * @package Canvas
15
 */
16
class Template
17
{
18
    /**
19
     * Given the email tempalte name and its params
20
     *  - create the files
21
     *  - render it with the variables
22
     *  - return the content string for use to use anywhere.
23
     *
24
     * @param string $name
25
     * @param array $params
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