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

EventCreatedListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A onEventCreated() 0 9 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
 * @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
}