Completed
Pull Request — master (#16)
by Christian
09:09
created

LanguageMapNormalizer::supportsNormalization()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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