Completed
Pull Request — master (#26)
by Dominik
02:16 queued 50s
created

EventCreatedListener::onEventCreated()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
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
 * @package Azine\MailgunWebhooksBundle\EventListener
11
 */
12
class EventCreatedListener
13
{
14
    /**
15
     * @var AzineMailgunMailerService
16
     */
17
    private $mailer;
18
19
    /**
20
     * @var bool
21
     */
22
    private $sendNotifications;
23
24
    /**
25
     * EventCreatedListener constructor.
26
     *
27
     * @param AzineMailgunMailerService $mailer
28
     * @param bool                $sendNotifications
29
     */
30
    public function __construct(AzineMailgunMailerService $mailer, $sendNotifications)
31
    {
32
        $this->mailer = $mailer;   
33
        $this->sendNotifications = $sendNotifications;
34
    }
35
36
    /**
37
     * @param MailgunWebhookEvent $event
38
     */
39
    public function onEventCreated(MailgunWebhookEvent $event)
40
    {
41
        $eventType = $event->getMailgunEvent()->getEvent();
42
        if ($eventType === 'complained') {
43
            if ($this->sendNotifications) {
44
                $this->mailer->sendSpamComplaintNotification($event->getMailgunEvent()->getId());                
45
            }
46
        }
47
    }
48
}