SendFeedbackHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\MessageHandler;
6
7
use App\Dto\FeedbackDto;
8
use App\Mailer\Mailer;
9
use App\Message\SendFeedback;
10
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
11
use Symfony\Component\Mime\Address;
12
use Symfony\Component\Mime\Email;
13
use Symfony\Contracts\Translation\TranslatorInterface;
14
15
final class SendFeedbackHandler implements MessageHandlerInterface
16
{
17
    private Mailer $mailer;
18
    private TranslatorInterface $translator;
19
20
    public function __construct(Mailer $mailer, TranslatorInterface $translator)
21
    {
22
        $this->mailer = $mailer;
23
        $this->translator = $translator;
24
    }
25
26
    public function __invoke(SendFeedback $sendFeedback): void
27
    {
28
        /** @var FeedbackDto $feedback */
29
        $feedback = $sendFeedback->getFeedback();
30
31
        $subject = $this->translator->trans('email.new_message');
32
33
        $email = (new Email())
34
            ->from(new Address($feedback->getFromEmail(), $feedback->getFromName()))
0 ignored issues
show
Bug introduced by
It seems like $feedback->getFromEmail() can also be of type null; however, parameter $address of Symfony\Component\Mime\Address::__construct() 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

34
            ->from(new Address(/** @scrutinizer ignore-type */ $feedback->getFromEmail(), $feedback->getFromName()))
Loading history...
Bug introduced by
It seems like $feedback->getFromName() can also be of type null; however, parameter $name of Symfony\Component\Mime\Address::__construct() 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

34
            ->from(new Address($feedback->getFromEmail(), /** @scrutinizer ignore-type */ $feedback->getFromName()))
Loading history...
35
            ->to($feedback->getToEmail())
0 ignored issues
show
Bug introduced by
It seems like $feedback->getToEmail() can also be of type null; however, parameter $addresses of Symfony\Component\Mime\Email::to() does only seem to accept Symfony\Component\Mime\Address|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

35
            ->to(/** @scrutinizer ignore-type */ $feedback->getToEmail())
Loading history...
36
            ->replyTo($feedback->getFromEmail())
0 ignored issues
show
Bug introduced by
It seems like $feedback->getFromEmail() can also be of type null; however, parameter $addresses of Symfony\Component\Mime\Email::replyTo() does only seem to accept Symfony\Component\Mime\Address|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

36
            ->replyTo(/** @scrutinizer ignore-type */ $feedback->getFromEmail())
Loading history...
37
            ->subject($subject)
38
            ->text($feedback->getMessage())
39
            ->html($feedback->getMessage());
40
41
        $this->mailer->send($email);
42
    }
43
}
44