Completed
Push — master ( dd73dd...675fe0 )
by WEBEWEB
02:20
created

EventDispatcherHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 23
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\EventDispatcher;
15
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
16
use Symfony\Component\HttpKernel\Kernel;
17
use WBW\Bundle\CoreBundle\Component\BaseEvent;
18
19
/**
20
 * Event dispatcher helper.
21
 *
22
 * @author webeweb <https://github.com/webeweb/>
23
 * @package WBW\Bundle\CoreBundle\EventDispatcher
24
 */
25
class EventDispatcherHelper {
26
27
    /**
28
     * Dispatch an event.
29
     *
30
     * @param EventDispatcherInterface|null $eventDispatcher The event dispatcher.
31
     * @param string $eventName The event name.
32
     * @param BaseEvent $event The event.
33
     * @return BaseEvent|null Returns the event in case of success, null otherwise.
34
     */
35
    public static function dispatch(EventDispatcherInterface $eventDispatcher = null, $eventName, BaseEvent $event) {
36
37
        if (null === $eventDispatcher || false === $eventDispatcher->hasListeners($eventName)) {
38
            return null;
39
        }
40
41
        if (Kernel::VERSION_ID < 40300) {
42
            return $eventDispatcher->dispatch($eventName, $event);
43
        }
44
45
        return $eventDispatcher->dispatch($event, $eventName);
46
    }
47
}
48