Passed
Push — master ( 87e26c...e69d87 )
by WEBEWEB
41:09
created

EventDispatcherHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 23
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 12 4
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2019 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\CoreBundle\EventDispatcher;
13
14
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
15
use Symfony\Component\HttpKernel\Kernel;
16
use WBW\Bundle\CoreBundle\Component\BaseEvent;
17
18
/**
19
 * Event dispatcher helper.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\CoreBundle\EventDispatcher
23
 */
24
class EventDispatcherHelper {
25
26
    /**
27
     * Dispatch an event.
28
     *
29
     * @param EventDispatcherInterface|null $eventDispatcher The event dispatcher.
30
     * @param string $eventName The event name.
31
     * @param BaseEvent $event The event.
32
     * @return BaseEvent|null Returns the event in case of success, null otherwise.
33
     */
34 45
    public static function dispatch(EventDispatcherInterface $eventDispatcher = null, string $eventName, BaseEvent $event): ?BaseEvent {
35
36 45
        if (null === $eventDispatcher || false === $eventDispatcher->hasListeners($eventName)) {
37 18
            return null;
38
        }
39
40 27
        if (Kernel::VERSION_ID < 40300) {
41 9
            return $eventDispatcher->dispatch($eventName, $event);
42
        }
43
44 18
        return $eventDispatcher->dispatch($event, $eventName);
45
    }
46
}
47