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

EventDispatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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