SymfonySerializerAdapter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 35
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A serialize() 0 8 2
A deserialize() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\IsmpClient\Impl\Serializer;
6
7
use Lamoda\IsmpClient\Exception\IsmpSerializerErrorException;
8
use Lamoda\IsmpClient\Serializer\SerializerInterface;
9
use Symfony\Component\Serializer\Serializer as SymfonySerializer;
10
11
final class SymfonySerializerAdapter implements SerializerInterface
12
{
13
    /**
14
     * @var SymfonySerializer
15
     */
16
    private $serializer;
17
18 14
    public function __construct(SymfonySerializer $serializer)
19
    {
20 14
        $this->serializer = $serializer;
21 14
    }
22
23 4
    public function serialize(object $object)
24
    {
25
        try {
26 4
            return $this->serializer->serialize($object, 'json');
27 2
        } catch (\Throwable $throwable) {
28 2
            throw IsmpSerializerErrorException::becauseOfError($throwable);
29
        }
30
    }
31
32 10
    public function deserialize(string $class, $data): object
33
    {
34
        try {
35 10
            return $this->serializer->deserialize(
36 10
                $data,
37 10
                $class,
38 10
                'json',
39 10
                ['disable_type_enforcement' => true]
40
            );
41 2
        } catch (\Throwable $throwable) {
42 2
            throw IsmpSerializerErrorException::becauseOfError($throwable);
43
        }
44
    }
45
}
46