Serializer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 55
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getContentTypes() 0 3 1
A normalize() 0 3 1
A __construct() 0 4 1
A encode() 0 3 1
A serialize() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Serialization;
6
7
use Chubbyphp\Serialization\Encoder\EncoderInterface;
8
use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface;
9
use Chubbyphp\Serialization\Normalizer\NormalizerInterface;
10
11
final class Serializer implements SerializerInterface
12
{
13
    /**
14
     * @var NormalizerInterface
15
     */
16
    private $normalizer;
17
18
    /**
19
     * @var EncoderInterface
20
     */
21
    private $encoder;
22
23
    public function __construct(NormalizerInterface $normalizer, EncoderInterface $encoder)
24
    {
25
        $this->normalizer = $normalizer;
26
        $this->encoder = $encoder;
27 4
    }
28
29 4
    /**
30 4
     * @param object $object
31 4
     * @param string $path
32
     */
33
    public function serialize(
34
        $object,
35
        string $contentType,
36
        NormalizerContextInterface $context = null,
37
        $path = ''
38
    ): string {
39
        return $this->encoder->encode($this->normalizer->normalize($object, $context, $path), $contentType);
40
    }
41 1
42
    /**
43
     * @param object $object
44
     *
45
     * @throws SerializerLogicException
46
     */
47 1
    public function normalize($object, NormalizerContextInterface $context = null, string $path = ''): array
48
    {
49
        return $this->normalizer->normalize($object, $context, $path);
50
    }
51
52
    /**
53
     * @return string[]
54
     */
55
    public function getContentTypes(): array
56
    {
57
        return $this->encoder->getContentTypes();
58
    }
59 1
60
    /**
61 1
     * @throws SerializerLogicException
62
     */
63
    public function encode(array $data, string $contentType): string
64
    {
65
        return $this->encoder->encode($data, $contentType);
66
    }
67
}
68