GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Mailer::createAndSendMessage()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.7857
c 0
b 0
f 0
cc 6
nc 6
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\InformationCollection\Core\Mailer;
6
7
use Netgen\InformationCollection\API\Exception\EmailNotSentException;
8
use Netgen\InformationCollection\API\MailerInterface;
9
use Netgen\InformationCollection\API\Value\DataTransfer\EmailContent;
10
11
class Mailer implements MailerInterface
12
{
13
    /**
14
     * @var \Swift_Mailer
15
     */
16
    protected $internalMailer;
17
18
    /**
19
     * Mailer constructor.
20
     *
21
     * @param \Swift_Mailer $internalMailer
22
     */
23
    public function __construct(\Swift_Mailer $internalMailer)
24
    {
25
        $this->internalMailer = $internalMailer;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function createAndSendMessage(EmailContent $data): void
32
    {
33
        $message = new \Swift_Message();
34
35
        try {
36
            $message->setTo($data->getRecipients());
37
        } catch (\Swift_RfcComplianceException $e) {
38
            throw new EmailNotSentException('recipients', $e->getMessage());
39
        }
40
41
        try {
42
            $message->setFrom($data->getSender());
43
        } catch (\Swift_RfcComplianceException $e) {
44
            throw new EmailNotSentException('sender', $e->getMessage());
45
        }
46
47
        $message->setSubject($data->getSubject());
48
        $message->setBody($data->getBody(), 'text/html');
49
50
        if ($data->hasAttachments()) {
51
            foreach ($data->getAttachments() as $attachment) {
52
                $message->attach(
53
                    \Swift_Attachment::fromPath($attachment->inputUri, $attachment->mimeType)
54
                        ->setFilename($attachment->fileName)
55
                );
56
            }
57
        }
58
59
        if (!$this->internalMailer->send($message)) {
60
            throw new EmailNotSentException('send', 'invalid mailer configuration?');
61
        }
62
    }
63
}
64