Completed
Push — master ( 739082...e6daa6 )
by Márk
03:21
created

QueueCommandNormalizer::denormalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 4
crap 1
1
<?php
2
3
namespace League\Tactician\Bernard;
4
5
use Assert\Assertion;
6
use Bernard\Normalizer\AbstractAggregateNormalizerAware;
7
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
8
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
9
10
class QueueCommandNormalizer extends AbstractAggregateNormalizerAware implements NormalizerInterface, DenormalizerInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 1
    public function normalize($object, $format = null, array $context = [])
16
    {
17
        return [
18 1
            'class' => get_class($object->getCommand()),
19 1
            'name' => $object->getName(),
20 1
            'data' => $this->aggregate->normalize($object->getCommand()),
21 1
        ];
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function supportsNormalization($data, $format = null)
28
    {
29
        return $data instanceof QueueCommand;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 1
    public function denormalize($data, $class, $format = null, array $context = [])
36
    {
37 1
        Assertion::choicesNotEmpty($data, ['class', 'name', 'data']);
38
39 1
        Assertion::classExists($data['class']);
40
41 1
        $object = new QueueCommand($this->aggregate->denormalize($data['data'], $data['class']), $data['name']);
42
43 1
        return $object;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function supportsDenormalization($data, $type, $format = null)
50
    {
51
        return $type === QueueCommand::class;
52
    }
53
}
54