TwigSwiftMailer::send()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminSecurityBundle\Mailer;
13
14
use Swift_Mailer;
15
16
class TwigSwiftMailer implements MailerInterface
17
{
18
    /**
19
     * @var Swift_Mailer
20
     */
21
    private $mailer;
22
23
    /**
24
     * @var SwiftMessageFactoryInterface
25
     */
26
    private $messageFactory;
27
28
    /**
29
     * @var string
30
     */
31
    private $templateName;
32
33
    /**
34
     * @var string
35
     */
36
    private $fromEmail;
37
38
    /**
39
     * @var string|null
40
     */
41
    private $replayToEmail;
42
43
    public function __construct(
44
        Swift_Mailer $mailer,
45
        SwiftMessageFactoryInterface $messageFactory,
46
        string $templateName,
47
        string $fromEmail,
48
        ?string $replayToEmail = null
49
    ) {
50
        $this->mailer = $mailer;
51
        $this->messageFactory = $messageFactory;
52
        $this->templateName = $templateName;
53
        $this->fromEmail = $fromEmail;
54
        $this->replayToEmail = $replayToEmail;
55
    }
56
57
    public function send(EmailableInterface $to): int
58
    {
59
        $message = $this->messageFactory->createMessage($to->getEmail(), $this->templateName, ['receiver' => $to]);
0 ignored issues
show
Bug introduced by
It seems like $to->getEmail() can also be of type null; however, parameter $email of FSi\Bundle\AdminSecurity...erface::createMessage() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
        $message = $this->messageFactory->createMessage(/** @scrutinizer ignore-type */ $to->getEmail(), $this->templateName, ['receiver' => $to]);
Loading history...
60
        $message->setFrom($this->fromEmail);
61
        if (null !== $this->replayToEmail) {
62
            $message->setReplyTo($this->replayToEmail);
63
        }
64
65
        return $this->mailer->send($message);
66
    }
67
}
68