Failed Conditions
Pull Request — master (#75)
by Yo
02:31
created

SymfonyJsonRpcServerDispatcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
dl 0
loc 33
ccs 0
cts 7
cp 0
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addJsonRpcListener() 0 3 1
A dispatchJsonRpcEvent() 0 5 2
A __construct() 0 3 1
1
<?php
2
namespace Yoanm\SymfonyJsonRpcHttpServer\Dispatcher;
3
4
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
5
use Yoanm\JsonRpcServer\Domain\Event\JsonRpcServerEvent;
6
use Yoanm\JsonRpcServer\Domain\JsonRpcServerDispatcherInterface;
7
use Yoanm\SymfonyJsonRpcHttpServer\Event\SymfonyJsonRpcServerEvent;
8
9
/**
10
 * Class SymfonyJsonRpcServerDispatcher
11
 */
12
class SymfonyJsonRpcServerDispatcher implements JsonRpcServerDispatcherInterface
13
{
14
    /** @var EventDispatcherInterface */
15
    private $symfonyEventDispatcher;
16
17
    /**
18
     * @param EventDispatcherInterface $symfonyEventDispatcher
19
     */
20
    public function __construct(EventDispatcherInterface $symfonyEventDispatcher)
21
    {
22
        $this->symfonyEventDispatcher = $symfonyEventDispatcher;
23
    }
24
25
    /**
26
     * @param string|null $eventName
27
     * @param JsonRpcServerEvent $event
28
     */
29
    public function dispatchJsonRpcEvent(string $eventName, JsonRpcServerEvent $event = null) : void
30
    {
31
        $this->symfonyEventDispatcher->dispatch(
32
            $event ? new SymfonyJsonRpcServerEvent($event) : new \stdClass(),
33
            $eventName
34
        );
35
    }
36
37
    /**
38
     * @param string   $eventName
39
     * @param callable $listener
40
     * @param int      $priority Default to 0
41
     */
42
    public function addJsonRpcListener(string $eventName, $listener, $priority = 0) : void
43
    {
44
        $this->symfonyEventDispatcher->addListener($eventName, $listener, $priority);
45
    }
46
}
47