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

Serializer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 4 1
A decode() 0 4 1
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