Completed
Push — master ( ffa60d...00bce6 )
by David
05:34
created

EventPublisherMixin::publish()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4286
cc 2
eloc 3
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Rawkode\Eidetic\EventStore;
4
5
trait EventPublisherMixin
6
{
7
    /**
8
     * @var array
9
     */
10
    private $eventSubscribers = [ ];
11
12
    /**
13
     * @param EventSubscriber $eventSubscriber
14
     */
15 2
    public function registerEventSubscriber($eventSubscriber)
16
    {
17 2
        array_push($this->eventSubscribers, $eventSubscriber);
18 2
    }
19
20
    /**
21
     * @param  int $eventHook
22
     * @param  object $event
23
     */
24 8
    public function publish($eventHook, $event)
25 1
    {
26
        /** @var EventSubscriber $eventSubscriber */
27 8
        foreach ($this->eventSubscribers as $eventSubscriber) {
28 2
            $eventSubscriber->handle($eventHook, $event);
29 8
        }
30 8
    }
31
}
32