Passed
Pull Request — release/2.0.0 (#26)
by Yo
02:53 queued 58s
created

addJsonRpcListener()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 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 3
    public function __construct(EventDispatcherInterface $symfonyEventDispatcher)
21
    {
22 3
        $this->symfonyEventDispatcher = $symfonyEventDispatcher;
23 3
    }
24
25
    /**
26
     * @param string $eventName
27
     * @param JsonRpcServerEvent|null $event
28
     */
29 2
    public function dispatchJsonRpcEvent(string $eventName, JsonRpcServerEvent $event = null) : void
30
    {
31 2
        $this->symfonyEventDispatcher->dispatch(
32 2
            $eventName,
33 2
            $event ? new SymfonyJsonRpcServerEvent($event) : null
34
        );
35 2
    }
36
37
    /**
38
     * @param string   $eventName
39
     * @param callable $listener
40
     * @param int      $priority Default to 0
41
     */
42 1
    public function addJsonRpcListener(string $eventName, $listener, $priority = 0) : void
43
    {
44 1
        $this->symfonyEventDispatcher->addListener($eventName, $listener, $priority);
45 1
    }
46
}
47