Test Failed
Pull Request — master (#8)
by Igor
13:01
created

ClientFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 8
c 1
b 0
f 0
dl 0
loc 19
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 $serializers;
29
30
    public function __construct(SerializerInterface $serializer, LoggerInterface $logger = null)
31
    {
32
        parent::__construct($logger);
33
34
        $this->serializers = [
35
            SerializationOptions::OBJECT_SERIALIZER  => new JsonObjectSerializer(),
36
            SerializationOptions::ARRAY_SERIALIZER   => new JsonArraySerializer(),
37
            SerializationOptions::SYMFONY_SERIALIZER => new SymfonySerializerAdapter($serializer),
38
        ];
39
    }
40
41
    protected function createSerializer(string $serializerType): MessageSerializerInterface
42
    {
43
        return $this->serializers[$serializerType];
44
    }
45
}
46