Test Failed
Branch master (354693)
by Valery
12:29
created

onContactFormSubmitted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 13
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Form\EventSubscriber;
6
7
use App\Entity\Contact;
8
use App\Event\ContactFormSubmittedEvent;
9
use App\Mailer\Sender\Adapter\SwiftMailerAdapter;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
use Symfony\Contracts\Translation\TranslatorInterface;
12
13
final class FeedbackNotificationSubscriber implements EventSubscriberInterface
14
{
15
    /**
16
     * @var SwiftMailerAdapter
17
     */
18
    private $mailer;
19
20
    /**
21
     * @var TranslatorInterface
22
     */
23
    private $translator;
24
25
    public function __construct(SwiftMailerAdapter $mailer, TranslatorInterface $translator)
26
    {
27
        $this->mailer = $mailer;
28
        $this->translator = $translator;
29
    }
30
31
    public static function getSubscribedEvents(): array
32
    {
33
        return [
34
            ContactFormSubmittedEvent::class => 'onContactFormSubmitted',
35
        ];
36
    }
37
38
    public function onContactFormSubmitted(ContactFormSubmittedEvent $event): void
39
    {
40
        /** @var Contact $contact */
41
        $contact = $event->getContact();
42
43
        $subject = $this->translator->trans('email.new_message');
44
45
        $this->mailer->send(
46
            $contact->getFromName(),
0 ignored issues
show
Bug introduced by
It seems like $contact->getFromName() can also be of type null; however, parameter $fromName of App\Mailer\Sender\Adapte...ftMailerAdapter::send() 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

46
            /** @scrutinizer ignore-type */ $contact->getFromName(),
Loading history...
47
            $contact->getFromEmail(),
0 ignored issues
show
Bug introduced by
It seems like $contact->getFromEmail() can also be of type null; however, parameter $fromEmail of App\Mailer\Sender\Adapte...ftMailerAdapter::send() 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

47
            /** @scrutinizer ignore-type */ $contact->getFromEmail(),
Loading history...
48
            $contact->getToEmail(),
0 ignored issues
show
Bug introduced by
It seems like $contact->getToEmail() can also be of type null; however, parameter $toEmail of App\Mailer\Sender\Adapte...ftMailerAdapter::send() 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

48
            /** @scrutinizer ignore-type */ $contact->getToEmail(),
Loading history...
49
            $subject,
50
            $contact->getMessage()
0 ignored issues
show
Bug introduced by
It seems like $contact->getMessage() can also be of type null; however, parameter $body of App\Mailer\Sender\Adapte...ftMailerAdapter::send() 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

50
            /** @scrutinizer ignore-type */ $contact->getMessage()
Loading history...
51
        );
52
    }
53
}
54