JsonFormat   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 18
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 10 2
A unserialize() 0 4 1
1
<?php
2
namespace Thunder\Serializard\Format;
3
4
use Thunder\Serializard\Exception\SerializationFailureException;
5
use Thunder\Serializard\NormalizerContainer\NormalizerContainerInterface as Normalizers;
6
use Thunder\Serializard\HydratorContainer\HydratorContainerInterface as Hydrators;
7
use Thunder\Serializard\NormalizerContext\NormalizerContextInterface;
8
9
/**
10
 * @author Tomasz Kowalczyk <[email protected]>
11
 */
12
final class JsonFormat extends AbstractFormat
13
{
14 7
    public function serialize($var, Normalizers $normalizers, NormalizerContextInterface $context)
15
    {
16 7
        $json = @json_encode($this->doSerialize($var, $normalizers, $context));
17
18 5
        if(json_last_error() !== JSON_ERROR_NONE) {
19 1
            throw SerializationFailureException::fromJson(json_last_error_msg());
20
        }
21
22 4
        return $json;
23
    }
24
25 4
    public function unserialize($var, $class, Hydrators $hydrators)
26
    {
27 4
        return $this->doUnserialize(json_decode($var, true), $class, $hydrators);
28
    }
29
}
30