Completed
Push — master ( 613d98...fa04c9 )
by Rémi
20:40
created

JsonSerializer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 4 1
A deserialize() 0 10 2
1
<?php
2
3
namespace Burrow\Serializer;
4
5
use Assert\Assertion;
6
use Burrow\Serializer;
7
8
class JsonSerializer implements Serializer
9
{
10
    /**
11
     * @param mixed $message
12
     *
13
     * @return string
14
     */
15
    public function serialize($message)
16
    {
17
        return json_encode($message);
18
    }
19
20
    /**
21
     * @param string $message
22
     *
23
     * @return mixed
24
     */
25
    public function deserialize($message)
26
    {
27
        if ($message === null) {
28
            return null;
29
        }
30
31
        Assertion::string($message, 'The message to deserialize must be a valid string');
32
33
        return json_decode($message);
34
    }
35
}
36