Transport   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A send() 0 9 1
1
<?php
2
/**
3
 * Communicator (https://github.com/waltertamboer/communicator)
4
 *
5
 * @link https://github.com/waltertamboer/communicator for the canonical source repository
6
 * @copyright Copyright (c) 2017 Communicator (https://github.com/waltertamboer/communicator)
7
 * @license https://github.com/waltertamboer/communicator/blob/master/LICENSE.md MIT
8
 */
9
10
namespace Communicator\Transport\Email;
11
12
use Communicator\Message;
13
use Communicator\Transport\Email\Resolver\ResolverInterface;
14
use Communicator\Transport\Email\Adapter\AdapterInterface;
15
use Communicator\Transport\TransportInterface;
16
17
/**
18
 * The e-mail transport will send an e-mail for the given message.
19
 */
20
class Transport implements TransportInterface
21
{
22
    /**
23
     * @var AdapterInterface
24
     */
25
    private $adapter;
26
27
    /**
28
     * @var ResolverInterface
29
     */
30
    private $resolver;
31
32
    /**
33
     * Initializes a new instance of this class.
34
     *
35
     * @param AdapterInterface $adapter
36
     * @param ResolverInterface $resolver
37
     */
38
    public function __construct(AdapterInterface $adapter, ResolverInterface $resolver)
39
    {
40
        $this->adapter = $adapter;
41
        $this->resolver = $resolver;
42
    }
43
44
    /**
45
     * Sends the message.
46
     *
47
     * @param array $recipients A list with all recipients that should receive the message.
48
     * @param Message $message The message to send.
49
     * @return void
50
     */
51
    public function send(array $recipients, Message $message): void
52
    {
53
        $text = $this->resolver->resolveTemplate($message, ResolverInterface::TYPE_TEXT);
54
        $html = $this->resolver->resolveTemplate($message, ResolverInterface::TYPE_HTML);
55
56
        $subject = $this->resolver->resolveSubject($message);
57
58
        $this->adapter->send($recipients, $message, $subject, $text, $html);
59
    }
60
}
61