Completed
Push — master ( a15a3c...decc90 )
by
unknown
04:44
created

JMSSerializer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 48
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A serialize() 0 4 1
A getSupportedFormats() 0 4 1
A getDefaultFormat() 0 4 1
1
<?php
2
3
namespace MediaMonks\RestApiBundle\Serializer;
4
5
use JMS\Serializer\Serializer;
6
use JMS\Serializer\SerializationContext;
7
use MediaMonks\RestApiBundle\Request\Format;
8
9
class JMSSerializer extends AbstractSerializer implements SerializerInterface
10
{
11
    /**
12
     * @var Serializer
13
     */
14
    private $serializer;
15
16
    /**
17
     * @var SerializationContext
18
     */
19
    private $context;
20
21
    /**
22
     * @param Serializer $serializer
23
     * @param SerializationContext|null $context
24
     */
25 4
    public function __construct(Serializer $serializer, SerializationContext $context = null)
26
    {
27 4
        $this->serializer = $serializer;
28 4
        $this->context = $context;
29 4
    }
30
31
    /**
32
     * @param $data
33
     * @param $format
34
     * @return mixed|string
35
     */
36 2
    public function serialize($data, $format)
37
    {
38 2
        return $this->serializer->serialize($data, $format, $this->context);
39
    }
40
41
    /**
42
     * @return array
43
     */
44 2
    public function getSupportedFormats()
45
    {
46 2
        return [Format::FORMAT_JSON, Format::FORMAT_XML];
47
    }
48
49
    /**
50
     * @return string
51
     */
52 1
    public function getDefaultFormat()
53
    {
54 1
        return Format::FORMAT_JSON;
55
    }
56
}
57