EnvelopeNormalizer::supportsNormalization()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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