Completed
Push — master ( a7df58...69cda4 )
by Toan
16s
created

Serializer::encode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright © 2017 Toan Nguyen. All rights reserved.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Gojira\Framework\Serializer;
10
11
use JMS\Serializer\SerializerBuilder;
12
13
/**
14
 * Base class for Serializer
15
 *
16
 * @package Gojira\Framework\Serializer
17
 * @author  Toan Nguyen <[email protected]>
18
 */
19
class Serializer implements SerializerInterface
20
{
21
    /**
22
     * Encode data to JSON-object
23
     *
24
     * @param array $data
25
     *
26
     * @return string
27
     */
28
    public static function encode(array $data)
29
    {
30
        return SerializerBuilder::create()->build()->serialize($data, 'json');
31
    }
32
33
    /**
34
     * Decode JSON-string to array
35
     *
36
     * @param string $data
37
     *
38
     * @return array
39
     */
40
    public static function decode($data)
41
    {
42
        return SerializerBuilder::create()->build()->deserialize($data, 'array', 'json');
43
    }
44
}
45