Serializer::getVideoSerializer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the XabbuhPandaClient package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\PandaClient\Serializer\Symfony;
13
14
use Symfony\Component\Serializer\Encoder\JsonEncoder;
15
use Symfony\Component\Serializer\Serializer as SymfonySerializer;
16
use Xabbuh\PandaClient\Serializer\SerializerInterface;
17
18
/**
19
 * Plugs the Symfony Serializer component into the Panda client.
20
 *
21
 * @author Christian Flothmann <[email protected]>
22
 */
23
class Serializer implements SerializerInterface
24
{
25
    /**
26
     * @var \Symfony\Component\Serializer\SerializerInterface
27
     */
28
    private $serializer;
29
30 27
    public function __construct()
31
    {
32 27
        $this->serializer = new SymfonySerializer(
33 27
            array(new Normalizer()), array(new JsonEncoder())
34
        );
35 27
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40
    public function serialize($data)
41
    {
42
        return $this->serializer->serialize($data, 'json');
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48 15
    public function deserialize($data, $type)
49
    {
50 15
        $fqcn = 'Xabbuh\PandaClient\Model\\'.$type;
51
52 15
        return $this->serializer->deserialize($data, $fqcn, 'json');
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58 9
    public static function getCloudSerializer()
59
    {
60 9
        return new Serializer();
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66 9
    public static function getEncodingSerializer()
67
    {
68 9
        return new Serializer();
69
    }
70
71
    /**
72
     * {@inheritDoc}
73
     */
74 9
    public static function getProfileSerializer()
75
    {
76 9
        return new Serializer();
77
    }
78
79
    /**
80
     * {@inheritDoc}
81
     */
82 9
    public static function getVideoSerializer()
83
    {
84 9
        return new Serializer();
85
    }
86
}
87