Completed
Push — master ( 60f2df...616eb8 )
by Saulius
12s
created

EventDispatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 25
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A dispatch() 0 6 2
1
<?php
2
/**
3
 * This file is part of the sauls/object-registry-bundle package.
4
 *
5
 * @author    Saulius Vaičeliūnas <[email protected]>
6
 * @link      http://saulius.vaiceliunas.lt
7
 * @copyright 2018
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Sauls\Bundle\ObjectRegistryBundle\EventDispatcher;
14
15
use Sauls\Bundle\ObjectRegistryBundle\Factory\EventNameFactoryInterface;
16
use Symfony\Component\EventDispatcher\Event;
17
use Symfony\Component\EventDispatcher\EventDispatcherInterface as SymfonyEventDispatcherInterface;
18
19
class EventDispatcher implements EventDispatcherInterface
20
{
21
    /**
22
     * @var SymfonyEventDispatcherInterface
23
     */
24
    private $eventDispatcher;
25
    /**
26
     * @var EventNameFactoryInterface
27
     */
28
    private $eventNameFactory;
29
30 1
    public function __construct(
31
        SymfonyEventDispatcherInterface $eventDispatcher,
32
        EventNameFactoryInterface $eventNameFactory
33
    ) {
34 1
        $this->eventDispatcher = $eventDispatcher;
35 1
        $this->eventNameFactory = $eventNameFactory;
36 1
    }
37
38 1
    public function dispatch(string $eventName, Event $event): void
39
    {
40 1
        $eventName = $this->eventNameFactory->create($eventName, $event);
41
42 1
        if ($this->eventDispatcher->hasListeners($eventName)) {
43 1
            $this->eventDispatcher->dispatch($eventName, $event);
44
        }
45 1
    }
46
}
47