Completed
Push — devel ( a59919...df32c1 )
by Alex
8s
created

JsonSerializer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 3
c 3
b 1
f 0
lcom 1
cbo 2
dl 0
loc 42
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A serialize() 0 4 1
A unserialize() 0 4 1
1
<?php
2
namespace PSB\Core\Serialization\Json;
3
4
5
class JsonSerializer
6
{
7
    /**
8
     * @var ObjectNormalizer
9
     */
10
    private $normalizer;
11
12
    /**
13
     * @var JsonEncoder
14
     */
15
    private $encoder;
16
17
    /**
18
     * @param ObjectNormalizer $normalizer
19
     * @param JsonEncoder      $encoder
20
     */
21 3
    public function __construct(ObjectNormalizer $normalizer, JsonEncoder $encoder)
22
    {
23 3
        $this->normalizer = $normalizer;
24 3
        $this->encoder = $encoder;
25 3
    }
26
27
    /**
28
     * @param object $object
29
     *
30
     * @return string
31
     */
32 1
    public function serialize($object)
33
    {
34 1
        return $this->encoder->encode($this->normalizer->normalize($object));
35
    }
36
37
    /**
38
     * @param string $json
39
     *
40
     * @return object
41
     */
42 1
    public function unserialize($json)
43
    {
44 1
        return $this->normalizer->denormalize($this->encoder->decode($json));
45
    }
46
}
47