FlushSenderSubscriber::onKernelTerminate()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 8.8571
cc 5
eloc 9
nc 5
nop 0
1
<?php
2
3
namespace DoS\SMSBundle\EventListener;
4
5
use SmsSender\DelayedSenderInterface;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
use Symfony\Component\DependencyInjection\IntrospectableContainerInterface;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
use Symfony\Component\HttpKernel\KernelEvents;
10
11
class FlushSenderSubscriber implements EventSubscriberInterface
12
{
13
    protected $container;
14
15
    public function __construct(ContainerInterface $container)
16
    {
17
        $this->container = $container;
18
    }
19
20
    public static function getSubscribedEvents()
21
    {
22
        return array(KernelEvents::TERMINATE => 'onKernelTerminate');
23
    }
24
25
    public function onKernelTerminate()
26
    {
27
        if (!$this->container->has('dos.sms.sender')) {
28
            return;
29
        }
30
31
        $senderInitialized = $this->container instanceof IntrospectableContainerInterface
32
            ? $this->container->initialized('dos.sms.sender')
33
            : true;
34
35
        if (!$senderInitialized || !$this->container->get('dos.sms.sender') instanceof DelayedSenderInterface) {
36
            return;
37
        }
38
39
        $this->container->get('dos.sms.sender')->flush();
40
    }
41
}
42