ManageFailedEventSubscriber   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 56
ccs 0
cts 19
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A onFail() 0 10 2
1
<?php
2
3
namespace Itkg\DelayEventBundle\EventListener;
4
5
use Itkg\DelayEventBundle\DomainManager\EventManagerInterface;
6
use Itkg\DelayEventBundle\Event\FailProcessedEvent;
7
use Itkg\DelayEventBundle\Event\ProcessedEvents;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10
/**
11
 * class ManageFailedEventSubscriber 
12
 */
13
class ManageFailedEventSubscriber implements EventSubscriberInterface
14
{
15
    /**
16
     * @var EventManagerInterface
17
     */
18
    private $eventManager;
19
20
    /**
21
     * @param EventManagerInterface $eventManager
22
     */
23
    public function __construct(EventManagerInterface $eventManager)
24
    {
25
        $this->eventManager = $eventManager;
26
    }
27
28
    /**
29
     * Returns an array of event names this subscriber wants to listen to.
30
     *
31
     * The array keys are event names and the value can be:
32
     *
33
     *  * The method name to call (priority defaults to 0)
34
     *  * An array composed of the method name to call and the priority
35
     *  * An array of arrays composed of the method names to call and respective
36
     *    priorities, or 0 if unset
37
     *
38
     * For instance:
39
     *
40
     *  * array('eventName' => 'methodName')
41
     *  * array('eventName' => array('methodName', $priority))
42
     *  * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
43
     *
44
     * @return array The event names to listen to
45
     *
46
     * @api
47
     */
48
    public static function getSubscribedEvents()
49
    {
50
        return array(
51
            ProcessedEvents::FAIL => 'onFail'
52
        );
53
    }
54
55
    /**
56
     * @param FailProcessedEvent $processedEvent
57
     */
58
    public function onFail(FailProcessedEvent $processedEvent)
59
    {
60
        $event = $processedEvent->getEvent();
61
        $event->increaseTryCount();
62
        if ($event->getTryCount() >= $processedEvent->getMaxRetryCount()) {
63
            $event->setFailed(true);
64
        }
65
66
        $this->eventManager->save($event);
67
    }
68
}
69