DefaultMessageConfigurator::configure()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 10
cp 0
rs 9.7
c 0
b 0
f 0
cc 3
nc 2
nop 2
crap 12
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