FailoverEventDispatcher   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B doDispatch() 0 25 6
1
<?php
2
namespace Workana\AsyncJobs\EventDispatching;
3
4
use Exception;
5
use Throwable;
6
use Symfony\Component\EventDispatcher\EventDispatcher;
7
use Symfony\Component\EventDispatcher\Event;
8
9
/**
10
 * Failover event dispatcher
11
 *
12
 * @author Carlos Frutos <[email protected]>
13
 */
14
class FailoverEventDispatcher extends EventDispatcher
15
{
16
    /**
17
     * {@inheritDoc}
18
     *
19
     * @throws AggregateRootEventException
20
     */
21
    protected function doDispatch($listeners, $eventName, Event $event)
22
    {
23
        /**
24
         * Array of arrays of type [$callable, $reason]
25
         */
26
        $failedListeners = [];
27
28
        foreach ($listeners as $listener) {
29
            try {
30
                call_user_func($listener, $event, $eventName, $this);
31
            } catch (Throwable $t) {
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
32
                $failedListeners[] = [$listener, $t];
33
            } catch (Exception $e) {
34
                $failedListeners[] = [$listener, $e];
35
            }
36
            
37
            if ($event->isPropagationStopped()) {
38
                break;
39
            }
40
        }
41
42
        if (!empty($failedListeners)) {
43
            throw new AggregateRootEventException($eventName, $event, $failedListeners);
44
        }
45
    }
46
}