Passed
Push — master ( 43534e...6dc374 )
by Alex
01:15 queued 12s
created

EventDispatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addListenerForEvent() 0 3 1
A addListenersForEvent() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\EventDispatcher;
6
7
use Arp\EventDispatcher\Listener\AddableListenerProviderInterface;
8
use Arp\EventDispatcher\Listener\AddListenerAwareInterface;
9
use Arp\EventDispatcher\Listener\Exception\EventListenerException;
10
11
/**
12
 * @author  Alex Patterson <[email protected]>
13
 * @package Arp\EventDispatcher
14
 */
15
final class EventDispatcher extends AbstractEventDispatcher implements AddListenerAwareInterface
16
{
17
    /**
18
     * @var AddableListenerProviderInterface
19
     */
20
    protected $listenerProvider;
21
22
    /**
23
     * @param AddableListenerProviderInterface $listenerProvider
24
     */
25
    public function __construct(AddableListenerProviderInterface $listenerProvider)
26
    {
27
        $this->listenerProvider = $listenerProvider;
28
    }
29
30
    /**
31
     * Add a new event listener to the collection.
32
     *
33
     * @param object|string $event    The event that should be attached to.
34
     * @param callable      $listener The event listener to attach.
35
     * @param int           $priority The event priority.
36
     *
37
     * @throws EventListenerException  If the event listener cannot be added.
38
     */
39
    public function addListenerForEvent($event, callable $listener, int $priority = 1): void
40
    {
41
        $this->listenerProvider->addListenerForEvent($event, $listener, $priority);
42
    }
43
44
    /**
45
     * Add a collection of event listeners for a single event.
46
     *
47
     * @param object|string       $event     The event name or instance to attach to.
48
     * @param iterable|callable[] $listeners Collection of listeners to attach.
49
     * @param int                 $priority  Event priority to use for all $listeners. This will default to 1.
50
     *
51
     * @throws EventListenerException  If the event listeners cannot be added.
52
     */
53
    public function addListenersForEvent($event, iterable $listeners, int $priority = 1): void
54
    {
55
        $this->listenerProvider->addListenersForEvent($event, $listeners, $priority);
56
    }
57
}
58