ClientFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 8
c 1
b 0
f 0
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createSerializer() 0 3 1
A __construct() 0 8 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