Test Failed
Push — master ( 29a35b...461fcb )
by Igor
14:38 queued 11:26
created

ClientFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 2
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