Completed
Pull Request — master (#1)
by Christian
02:39
created

DocumentDataNormalizer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 38
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 8 2
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\DocumentData;
17
18
/**
19
 * @author Christian Flothmann <[email protected]>
20
 */
21
final class DocumentDataNormalizer implements DenormalizerInterface, NormalizerInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function normalize($object, $format = null, array $context = array())
27
    {
28
        if (!$object instanceof DocumentData) {
29
            return null;
30
        }
31
32
        return $object->getData();
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function supportsNormalization($data, $format = null)
39
    {
40
        return $data instanceof DocumentData;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function denormalize($data, $class, $format = null, array $context = array())
47
    {
48
        return new DocumentData($data);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function supportsDenormalization($data, $type, $format = null)
55
    {
56
        return 'Xabbuh\XApi\Model\DocumentData' === $type;
57
    }
58
}
59