Completed
Push — master ( d43734...ab0406 )
by Tomasz
03:38
created

JsonFormat::unserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
crap 1
1
<?php
2
namespace Thunder\Serializard\Format;
3
4
use Thunder\Serializard\NormalizerContainer\NormalizerContainerInterface as Normalizers;
5
use Thunder\Serializard\HydratorContainer\HydratorContainerInterface as Hydrators;
6
7
/**
8
 * @author Tomasz Kowalczyk <[email protected]>
9
 */
10
final class JsonFormat extends AbstractFormat
11
{
12 5
    public function serialize($var, Normalizers $normalizers)
13
    {
14 5
        $json = json_encode($this->doSerialize($var, $normalizers));
15
16 2
        if(json_last_error() !== JSON_ERROR_NONE) {
17
            throw new \RuntimeException(sprintf('JSON serialization failure: `%s`!', json_last_error_msg()));
18
        }
19
20 2
        return $json;
21
    }
22
23 2
    public function unserialize($var, $class, Hydrators $hydrators)
24
    {
25 2
        return $this->doUnserialize(json_decode($var, true), $class, $hydrators);
26
    }
27
}
28