Passed
Pull Request — master (#7)
by Igor
04:31
created

SymfonySerializerAdapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 3 1
A __construct() 0 3 1
A deserialize() 0 3 1
1
<?php
2
/*
3
 * This file is part of JSON RPC Client.
4
 *
5
 * (c) Igor Lazarev <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Strider2038\JsonRpcClient\Bridge\Symfony\Serialization;
12
13
use Strider2038\JsonRpcClient\Response\ResponseObjectInterface;
14
use Strider2038\JsonRpcClient\Serialization\MessageSerializerInterface;
15
use Symfony\Component\Serializer\SerializerInterface;
16
17
/**
18
 * @author Igor Lazarev <[email protected]>
19
 */
20
class SymfonySerializerAdapter implements MessageSerializerInterface
21
{
22
    /** @var SerializerInterface */
23
    private $serializer;
24
25 6
    public function __construct(SerializerInterface $serializer)
26
    {
27 6
        $this->serializer = $serializer;
28 6
    }
29
30 4
    public function serialize($request): string
31
    {
32 4
        return $this->serializer->serialize($request, 'json');
33
    }
34
35 4
    public function deserialize(string $response, array $context)
36
    {
37 4
        return $this->serializer->deserialize($response, ResponseObjectInterface::class, 'json', $context);
38
    }
39
}
40