Passed
Push — master ( 72ba5d...808b88 )
by Yo
01:00 queued 10s
created

JsonRpcServerDispatcherAwareTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 24
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setJsonRpcServerDispatcher() 0 3 1
A dispatchJsonRpcEvent() 0 5 2
1
<?php
2
namespace Yoanm\JsonRpcServer\App\Dispatcher;
3
4
use Yoanm\JsonRpcServer\Domain\Event\JsonRpcServerEvent;
5
use Yoanm\JsonRpcServer\Domain\JsonRpcServerDispatcherInterface;
6
7
/**
8
 * Class JsonRpcServerDispatcherAwareTrait
9
 */
10
trait JsonRpcServerDispatcherAwareTrait
11
{
12
    /** @var JsonRpcServerDispatcherInterface */
13
    private $jsonRpcServerDispatcher = null;
14
15
    /**
16
     * @param JsonRpcServerDispatcherInterface $jsonRpcServerDispatcher
17
     */
18 6
    public function setJsonRpcServerDispatcher(JsonRpcServerDispatcherInterface $jsonRpcServerDispatcher) : void
19
    {
20 6
        $this->jsonRpcServerDispatcher = $jsonRpcServerDispatcher;
21 6
    }
22
23
    /**
24
     * @param string                  $eventName
25
     * @param JsonRpcServerEvent|null $event
26
     *
27
     * @return void
28
     */
29 20
    protected function dispatchJsonRpcEvent(string $eventName, JsonRpcServerEvent $event = null) : void
30
    {
31
        // Do nothing if dispatcher is not there
32 20
        if ($this->jsonRpcServerDispatcher) {
33 5
            $this->jsonRpcServerDispatcher->dispatchJsonRpcEvent($eventName, $event);
34
        }
35 20
    }
36
}
37