CommandSerializationHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 41
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A serialize() 0 7 1
A deserialize() 0 4 1
A getSubscribingMethods() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\TacticianQueue\Serializer;
6
7
use JMS\Serializer\Context;
8
use JMS\Serializer\GraphNavigator;
9
use JMS\Serializer\Handler\SubscribingHandlerInterface;
10
use JMS\Serializer\JsonDeserializationVisitor;
11
use JMS\Serializer\JsonSerializationVisitor;
12
use Symfony\Component\Serializer\Serializer;
13
14
final class CommandSerializationHandler implements SubscribingHandlerInterface
15
{
16
    /** @var Serializer */
17
    private $serializer;
18
19
    public function __construct(Serializer $serializer)
20
    {
21
        $this->serializer = $serializer;
22
    }
23
24
    public function serialize(JsonSerializationVisitor $visitor, $command, array $type, Context $context): array
0 ignored issues
show
Unused Code introduced by
The parameter $visitor is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
        return [
27
            'command' => get_class($command),
28
            'properties' => json_decode($this->serializer->serialize($command, 'json'), true),
29
        ];
30
    }
31
32
    public function deserialize(JsonDeserializationVisitor $visitor, $data, array $type)
0 ignored issues
show
Unused Code introduced by
The parameter $visitor is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    {
34
        return $this->serializer->deserialize(json_encode($data['properties']), $data['command'], 'json');
35
    }
36
37
    public static function getSubscribingMethods()
38
    {
39
        return [
40
            [
41
                'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
42
                'format' => 'json',
43
                'type' => 'tactician_command',
44
                'method' => 'serialize',
45
            ],
46
            [
47
                'direction' => GraphNavigator::DIRECTION_DESERIALIZATION,
48
                'format' => 'json',
49
                'type' => 'tactician_command',
50
                'method' => 'deserialize',
51
            ],
52
        ];
53
    }
54
}
55