TwigUserMailableFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A build() 0 9 1
1
<?php
2
3
/*
4
 * This file is part of the BenGorUser package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorUser\TwigBridge\Infrastructure\Mailing;
14
15
use BenGorUser\User\Domain\Model\UserEmail;
16
use BenGorUser\User\Domain\Model\UserMailable;
17
use BenGorUser\User\Domain\Model\UserMailableFactory;
18
19
/**
20
 * Twig implementation of user mailable factory domain class.
21
 *
22
 * @author Beñat Espiña <[email protected]>
23
 * @author Gorka Laucirica <[email protected]>
24
 */
25
final class TwigUserMailableFactory implements UserMailableFactory
26
{
27
    /**
28
     * The from email address.
29
     *
30
     * @var string
31
     */
32
    private $from;
33
34
    /**
35
     * The Twig.
36
     *
37
     * @var \Twig_Environment
38
     */
39
    private $twig;
40
41
    /**
42
     * The view name.
43
     *
44
     * @var string
45
     */
46
    private $view;
47
48
    /**
49
     * Constructor.
50
     *
51
     * @param \Twig_Environment $twig  The Twig environment
52
     * @param string            $aView The view name
53
     * @param string            $aFrom The from email address
54
     */
55
    public function __construct(\Twig_Environment $twig, $aView, $aFrom)
56
    {
57
        $this->twig = $twig;
58
        $this->view = $aView;
59
        $this->from = $aFrom;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function build($to, array $parameters = [])
66
    {
67
        $template = $this->twig->loadTemplate($this->view);
68
        $subject = $template->renderBlock('subject', $parameters);
69
        $bodyText = $template->renderBlock('body_text', $parameters);
70
        $bodyHtml = $template->renderBlock('body_html', $parameters);
71
72
        return new UserMailable($to, new UserEmail($this->from), $subject, $bodyText, $bodyHtml);
73
    }
74
}
75