Completed
Push — master ( beeeff...e349d6 )
by Christian
07:48 queued 05:00
created

InteractionComponentNormalizer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 52
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsNormalization() 0 4 1
A supportsDenormalization() 0 4 1
A normalize() 0 16 3
A denormalize() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Serializer\Normalizer;
13
14
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
15
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
16
use Xabbuh\XApi\Model\Interaction\InteractionComponent;
17
18
/**
19
 * Denormalizes xAPI statement activity {@link InteractionComponent interaction components}.
20
 *
21
 * @author Christian Flothmann <[email protected]>
22
 */
23
final class InteractionComponentNormalizer extends Normalizer implements DenormalizerInterface, NormalizerInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 8
    public function normalize($object, $format = null, array $context = array())
29
    {
30 8
        if (!$object instanceof InteractionComponent) {
31
            return;
32
        }
33
34
        $data = array(
35 8
            'id' => $object->getId(),
36
        );
37
38 8
        if (null !== $description = $object->getDescription()) {
39 1
            $data['description'] = $this->normalizeAttribute($description, $format, $context);
40
        }
41
42 8
        return $data;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 121
    public function supportsNormalization($data, $format = null)
49
    {
50 121
        return $data instanceof InteractionComponent;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 8
    public function denormalize($data, $class, $format = null, array $context = array())
57
    {
58 8
        $description = null;
59
60 8
        if (isset($data['description'])) {
61 1
            $description = $this->denormalizeData($data['description'], 'Xabbuh\XApi\Model\LanguageMap', $format, $context);
62
        }
63
64 8
        return new InteractionComponent($data['id'], $description);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 127
    public function supportsDenormalization($data, $type, $format = null)
71
    {
72 127
        return 'Xabbuh\XApi\Model\Interaction\InteractionComponent' === $type;
73
    }
74
}
75