RpcServer::setSerializer()   B
last analyzed

Complexity

Conditions 7
Paths 9

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 14
cts 14
cp 1
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 13
nc 9
nop 1
crap 7
1
<?php
2
3
namespace RabbitMqModule\Options;
4
5
use Zend\Serializer\Serializer;
6
use Zend\Serializer\Adapter\AdapterInterface as SerializerInterface;
7
8
/**
9
 * Class RpcServer
10
 * @package RabbitMqModule\Options
11
 */
12
class RpcServer extends Consumer
13
{
14
    /**
15
     * @var SerializerInterface
16
     */
17
    protected $serializer;
18
19
    /**
20
     * @return mixed
21
     */
22 2
    public function getSerializer()
23
    {
24 2
        return $this->serializer;
25
    }
26
27
    /**
28
     * @param null|string|array|SerializerInterface $serializer
29
     *
30
     * @return $this
31
     *
32
     * @throws \InvalidArgumentException
33
     */
34 4
    public function setSerializer($serializer = null)
35
    {
36 4
        if (is_array($serializer)) {
37 2
            if (!array_key_exists('name', $serializer)) {
38 1
                throw new \InvalidArgumentException('A serializer name should be provided');
39
            }
40 1
            $name = $serializer['name'];
41 1
            $options = array_key_exists('options', $serializer) ? $serializer['options'] : null;
42 1
            $serializer = Serializer::factory($name, $options);
43 3
        } elseif (is_string($serializer)) {
44 2
            $serializer = Serializer::factory($serializer);
45 2
        }
46 3
        if (null !== $serializer && !$serializer instanceof SerializerInterface) {
47 1
            throw new \InvalidArgumentException('Invalid serializer instance or options');
48
        }
49 2
        $this->serializer = $serializer;
50
51 2
        return $this;
52
    }
53
}
54