ClientFactory::createSerializer()   A
last analyzed

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
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
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\DependencyInjection\Factory;
12
13
use Psr\Log\LoggerInterface;
14
use Strider2038\JsonRpcClient\Bridge\Symfony\Serialization\SymfonySerializerAdapter;
15
use Strider2038\JsonRpcClient\ClientFactory as BaseClientFactory;
16
use Strider2038\JsonRpcClient\Configuration\SerializationOptions;
17
use Strider2038\JsonRpcClient\Serialization\JsonArraySerializer;
18
use Strider2038\JsonRpcClient\Serialization\JsonObjectSerializer;
19
use Strider2038\JsonRpcClient\Serialization\MessageSerializerInterface;
20
use Symfony\Component\Serializer\SerializerInterface;
21
22
/**
23
 * @author Igor Lazarev <[email protected]>
24
 */
25
class ClientFactory extends BaseClientFactory
26
{
27
    /** @var MessageSerializerInterface[] */
28
    private array $serializers;
29
30 5
    public function __construct(SerializerInterface $serializer, LoggerInterface $logger = null)
31
    {
32 5
        parent::__construct($logger);
33
34 5
        $this->serializers = [
35 5
            SerializationOptions::OBJECT_SERIALIZER  => new JsonObjectSerializer(),
36 5
            SerializationOptions::ARRAY_SERIALIZER   => new JsonArraySerializer(),
37 5
            SerializationOptions::SYMFONY_SERIALIZER => new SymfonySerializerAdapter($serializer),
38
        ];
39 5
    }
40
41 5
    protected function createSerializer(string $serializerType): MessageSerializerInterface
42
    {
43 5
        return $this->serializers[$serializerType];
44
    }
45
}
46