DefaultMessageConfigurator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 23
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A configure() 0 17 3
1
<?php
2
3
namespace Yokai\MessengerBundle\Channel\Swiftmailer\Configurator;
4
5
use Swift_Attachment;
6
use Swift_Message;
7
use Yokai\MessengerBundle\Delivery;
8
use Yokai\MessengerBundle\Recipient\EmailRecipientInterface;
9
10
/**
11
 * @author Yann Eugoné <[email protected]>
12
 */
13
class DefaultMessageConfigurator implements SwiftMessageConfiguratorInterface
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function configure(Swift_Message $message, Delivery $delivery)
19
    {
20
        $recipient = $delivery->getRecipient();
21
22
        $options = $delivery->getOptions();
23
24
        $message
25
            ->setSubject($delivery->getSubject())
26
            ->setFrom($options['from'])
27
            ->setTo($recipient instanceof EmailRecipientInterface ? $recipient->getEmail() : $recipient)
28
            ->setBody($delivery->getBody(), 'text/html')
29
        ;
30
31
        foreach ($delivery->getAttachments() as $file) {
32
            $message->attach(Swift_Attachment::fromPath($file->getPathname(), $file->getMimeType()));
33
        }
34
    }
35
}
36