JmsSerializer::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
1
<?php
2
3
namespace TreeHouse\Queue\Message\Serializer;
4
5
use JMS\Serializer\SerializationContext;
6
use JMS\Serializer\SerializerInterface as BaseSerializer;
7
8
class JmsSerializer implements SerializerInterface
9
{
10
    /**
11
     * @var BaseSerializer
12
     */
13
    protected $serializer;
14
15
    /**
16
     * @var SerializationContext
17
     */
18
    protected $context;
19
20
    /**
21
     * @var string
22
     */
23
    protected $format;
24
25
    /**
26
     * @param BaseSerializer       $serializer
27
     * @param string               $format
28
     * @param SerializationContext $context
29
     */
30 3
    public function __construct(BaseSerializer $serializer, $format = 'json', SerializationContext $context = null)
31
    {
32 3
        $this->serializer = $serializer;
33 3
        $this->format = $format;
34 3
        $this->context = $context ?: SerializationContext::create();
35 3
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40 2
    public function serialize($value)
41
    {
42 2
        return $this->serializer->serialize($value, $this->format, $this->context);
43
    }
44
}
45