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->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
![]() |
|||||
35 | ->to($feedback->getToEmail()) |
||||
0 ignored issues
–
show
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
![]() |
|||||
36 | ->replyTo($feedback->getFromEmail()) |
||||
0 ignored issues
–
show
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
![]() |
|||||
37 | ->subject($subject) |
||||
38 | ->text($feedback->getMessage()) |
||||
39 | ->html($feedback->getMessage()); |
||||
40 | |||||
41 | $this->mailer->send($email); |
||||
42 | } |
||||
43 | } |
||||
44 |