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.
Completed
Pull Request — master (#73)
by
unknown
14:32
created

SwiftMailerBasedMailer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 52
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B sendEmail() 0 31 6
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 Symfony\Component\Mime\Email;
10
11
class SwiftMailerBasedMailer 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 sendEmail(Email $content): void
32
    {
33
        $message = new \Swift_Message();
34
35
        try {
36
            $message->setTo($content->getFrom());
37
        } catch (\Swift_RfcComplianceException $e) {
38
            throw new EmailNotSentException('recipients', $e->getMessage());
39
        }
40
41
        try {
42
            $message->setFrom($data->getSender());
0 ignored issues
show
Bug introduced by
The variable $data does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
43
        } catch (\Swift_RfcComplianceException $e) {
44
            throw new EmailNotSentException('sender', $e->getMessage());
45
        }
46
47
        $message->setSubject($data->getSubject());
48
49
        if ($data->hasAttachments()) {
50
            foreach ($data->getAttachments() as $attachment) {
51
                $message->attach(
52
                    \Swift_Attachment::fromPath($attachment->inputUri, $attachment->mimeType)
53
                        ->setFilename($attachment->fileName)
54
                );
55
            }
56
        }
57
58
        if (!$this->internalMailer->send($message)) {
59
            throw new EmailNotSentException('send', 'invalid mailer configuration?');
60
        }
61
    }
62
}
63