EmailRenderer::renderTemplate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 13
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Common\Bridge\Twig;
6
7
use Damax\Common\Domain\Email\EmailRenderer as EmailRendererInterface;
8
use Damax\Common\Domain\Email\Template;
9
use Twig\Environment;
10
11
final class EmailRenderer implements EmailRendererInterface
12
{
13
    private $twig;
14
15
    public function __construct(Environment $twig)
16
    {
17
        $this->twig = $twig;
18
    }
19
20
    public function renderTemplate(string $templatePath, $context = []): Template
21
    {
22
        $template = $this->twig->load($templatePath);
23
24
        $subj = $template->renderBlock('subject', $context);
25
        $text = $template->renderBlock('text', $context);
26
        $html = null;
27
28
        if ($template->hasBlock('html', $context)) {
29
            $html = $template->renderBlock('html', $context);
30
        }
31
32
        return new Template($subj, $text, $html);
33
    }
34
}
35