Serializer::getContentTypes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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