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

SymfonySerializerAdapter::deserialize()   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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 2
crap 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