EmailRenderer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A renderTemplate() 0 13 2
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