Completed
Push — master ( 4c7b9c...e919dc )
by Kamil
21:11
created

ListenerRegistry   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 37
rs 10
c 2
b 1
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addListener() 0 6 1
A getListener() 0 8 2
A getListeners() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\FixturesBundle\Listener;
13
14
use Webmozart\Assert\Assert;
15
16
/**
17
 * @author Kamil Kokot <[email protected]>
18
 */
19
final class ListenerRegistry implements ListenerRegistryInterface
20
{
21
    /**
22
     * @var array
23
     */
24
    private $listeners = [];
25
26
    /**
27
     * @param ListenerInterface $listener
28
     */
29
    public function addListener(ListenerInterface $listener)
30
    {
31
        Assert::keyNotExists($this->listeners, $listener->getName(), 'Listener with name "%s" is already registered.');
32
33
        $this->listeners[$listener->getName()] = $listener;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getListener($name)
40
    {
41
        if (!isset($this->listeners[$name])) {
42
            throw new ListenerNotFoundException($name);
43
        }
44
45
        return $this->listeners[$name];
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getListeners()
52
    {
53
        return $this->listeners;
54
    }
55
}
56