Completed
Push — master ( b1744c...51aee2 )
by Matze
04:34
created

EventDispatcherTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 43
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setEventDispatcher() 0 4 1
A getDispatcher() 0 4 1
A dispatchEvent() 0 4 1
A dispatchInBackground() 0 4 1
1
<?php
2
3
namespace BrainExe\Core\Traits;
4
5
use BrainExe\Annotations\Annotations\Inject;
6
use BrainExe\Core\EventDispatcher\AbstractEvent;
7
use BrainExe\Core\EventDispatcher\EventDispatcher;
8
use BrainExe\Core\MessageQueue\Job;
9
10
/**
11
 * @api
12
 */
13
trait EventDispatcherTrait
14
{
15
16
    /**
17
     * @var EventDispatcher
18
     */
19
    private $dispatcher;
20
21
    /**
22
     * @Inject("@EventDispatcher")
23
     * @param EventDispatcher $dispatcher
24
     */
25 7
    public function setEventDispatcher(EventDispatcher $dispatcher)
26
    {
27 7
        $this->dispatcher = $dispatcher;
28 7
    }
29
30
    /**
31
     * @return EventDispatcher
32
     */
33
    public function getDispatcher() : EventDispatcher
34
    {
35
        return $this->dispatcher;
36
    }
37
38
    /**
39
     * @param AbstractEvent $event
40
     */
41 4
    public function dispatchEvent(AbstractEvent $event)
42
    {
43 4
        $this->dispatcher->dispatchEvent($event);
44 3
    }
45
46
    /**
47
     * @param AbstractEvent $event
48
     * @param int|null $timestamp
49
     * @return Job
50
     */
51 1
    public function dispatchInBackground(AbstractEvent $event, int $timestamp = 0)
52
    {
53 1
        return $this->dispatcher->dispatchInBackground($event, $timestamp);
54
    }
55
}
56