Serializard   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 31
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A serialize() 0 4 1
A unserialize() 0 4 1
A getNormalizerContext() 0 6 2
1
<?php
2
namespace Thunder\Serializard;
3
4
use Thunder\Serializard\FormatContainer\FormatContainerInterface as Formats;
5
use Thunder\Serializard\HydratorContainer\HydratorContainerInterface as Hydrators;
6
use Thunder\Serializard\NormalizerContainer\NormalizerContainerInterface as Normalizers;
7
use Thunder\Serializard\NormalizerContext\NormalizerContextInterface;
8
use Thunder\Serializard\NormalizerContext\ParentNormalizerContext;
9
10
/**
11
 * @author Tomasz Kowalczyk <[email protected]>
12
 */
13
final class Serializard
14
{
15
    private $normalizers;
16
    private $hydrators;
17
    /** @var Formats */
18
    private $formats;
19
20 13
    public function __construct(Formats $formats, Normalizers $normalizers, Hydrators $hydrators)
21
    {
22 13
        $this->normalizers = $normalizers;
23 13
        $this->hydrators = $hydrators;
24 13
        $this->formats = $formats;
25 13
    }
26
27 12
    public function serialize($var, $format, NormalizerContextInterface $context = null)
28
    {
29 12
        return $this->formats->get($format)->serialize($var, $this->normalizers, $this->getNormalizerContext($context, $var, $format));
30
    }
31
32 4
    public function unserialize($var, $class, $format)
33
    {
34 4
        return $this->formats->get($format)->unserialize($var, $class, $this->hydrators);
35
    }
36
37 11
    private function getNormalizerContext(NormalizerContextInterface $context = null, $var, $format)
38
    {
39 11
        $context = $context ?: new ParentNormalizerContext();
40
41 11
        return $context->withRoot($var)->withFormat($format);
42
    }
43
}
44