Assembler::assemble()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 3
1
<?php
2
3
namespace T4web\Mail;
4
5
use Zend\Mail\Message;
6
use Zend\Mime\Message as MimeMessage;
7
use Zend\Mime\Part as MimePart;
8
9
class Assembler
10
{
11
    /**
12
     * @var array
13
     */
14
    private $config;
15
16
    public function __construct(
17
        array $config
18
    ) {
19
        $this->config = $config;
20
    }
21
22
    /**
23
     * @param string $to
24
     * @param Template $template
25
     * @param array $data
26
     * @return Message
27
     */
28
    public function assemble($to, Template $template, array $data)
29
    {
30
        $html = new MimePart($template->getBody($data));
31
        $html->type = "text/html";
32
        $body = new MimeMessage();
33
        $body->addPart($html);
34
35
        $message = new Message();
36
37
        $message
38
            ->addFrom($this->config['from-email'], $this->config['from-name'])
39
            ->addTo($to)
40
            ->setSubject($template->getSubject())
41
            ->setBody($body)
42
            ->setEncoding("UTF-8");
43
44
        return $message;
45
    }
46
}