Assembler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A assemble() 0 18 1
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
}