EventCreatedListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 9
c 2
b 1
f 0
dl 0
loc 33
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onEventCreated() 0 6 3
1
<?php
2
3
namespace Azine\MailgunWebhooksBundle\EventListener;
4
5
use Azine\MailgunWebhooksBundle\Entity\MailgunWebhookEvent;
6
use Azine\MailgunWebhooksBundle\Services\AzineMailgunMailerService;
7
8
/**
9
 * Class EventCreatedListener.
10
 */
11
class EventCreatedListener
12
{
13
    /**
14
     * @var AzineMailgunMailerService
15
     */
16
    private $mailer;
17
18
    /**
19
     * @var bool
20
     */
21
    private $sendNotifications;
22
23
    /**
24
     * EventCreatedListener constructor.
25
     *
26
     * @param AzineMailgunMailerService $mailer
27
     * @param bool                      $sendNotifications
28
     */
29
    public function __construct(AzineMailgunMailerService $mailer, $sendNotifications)
30
    {
31
        $this->mailer = $mailer;
32
        $this->sendNotifications = $sendNotifications;
33
    }
34
35
    /**
36
     * @param MailgunWebhookEvent $event
37
     */
38
    public function onEventCreated(MailgunWebhookEvent $event)
39
    {
40
        $eventType = $event->getMailgunEvent()->getEvent();
41
        if ('complained' === $eventType) {
42
            if ($this->sendNotifications) {
43
                $this->mailer->sendSpamComplaintNotification($event->getMailgunEvent()->getId());
44
            }
45
        }
46
    }
47
}
48