Completed
Push — master ( b458df...beeeff )
by Christian
06:18 queued 04:09
created

LanguageMapNormalizer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 44
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 14 3
A supportsNormalization() 0 4 1
A denormalize() 0 4 1
A supportsDenormalization() 0 4 1
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\LanguageMap;
17
18
/**
19
 * Normalizes and denormalizes {@link LanguageMap} instances.
20
 *
21
 * @author Christian Flothmann <[email protected]>
22
 */
23
final class LanguageMapNormalizer implements DenormalizerInterface, NormalizerInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 36
    public function normalize($object, $format = null, array $context = array())
29
    {
30 36
        if (!$object instanceof LanguageMap) {
31
            return;
32
        }
33
34 36
        $map = array();
35
36 36
        foreach ($object->languageTags() as $languageTag) {
37 36
            $map[$languageTag] = $object[$languageTag];
38
        }
39
40 36
        return $map;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 117
    public function supportsNormalization($data, $format = null)
47
    {
48 117
        return $data instanceof LanguageMap;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 40
    public function denormalize($data, $class, $format = null, array $context = array())
55
    {
56 40
        return LanguageMap::create($data);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 119
    public function supportsDenormalization($data, $type, $format = null)
63
    {
64 119
        return 'Xabbuh\XApi\Model\LanguageMap' === $type;
65
    }
66
}
67