EnvelopeNormalizer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 7
dl 0
loc 25
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A denormalize() 0 3 1
A supportsDenormalization() 0 3 1
A supportsNormalization() 0 3 1
A normalize() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Enqueue\SimpleBus\Bridge\Symfony\Serializer;
6
7
use SimpleBus\Serialization\Envelope\DefaultEnvelope;
8
use SimpleBus\Serialization\Envelope\Envelope;
9
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
10
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
11
12
class EnvelopeNormalizer implements NormalizerInterface, DenormalizerInterface
13
{
14
    public function normalize($object, $format = null, array $context = [])
15
    {
16
        /* @var Envelope $object */
17
18
        return [
19
            'type' => $object->messageType(),
20
            'message' => $object->serializedMessage(),
21
        ];
22
    }
23
24
    public function denormalize($data, $class, $format = null, array $context = [])
25
    {
26
        return DefaultEnvelope::forSerializedMessage($data['type'], $data['message']);
27
    }
28
29
    public function supportsNormalization($data, $format = null): bool
30
    {
31
        return $data instanceof Envelope;
32
    }
33
34
    public function supportsDenormalization($data, $type, $format = null): bool
35
    {
36
        return is_a($type, Envelope::class, true);
37
    }
38
}
39