Completed
Push — master ( 6dd36b...4e0b95 )
by Christian
02:36
created

DocumentDataNormalizer::denormalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 4
crap 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
 * Normalizes and denormalizes xAPI statement documents.
20
 *
21
 * @author Christian Flothmann <[email protected]>
22
 */
23
final class DocumentDataNormalizer implements DenormalizerInterface, NormalizerInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function normalize($object, $format = null, array $context = array())
29
    {
30 1
        if (!$object instanceof DocumentData) {
31
            return null;
32
        }
33
34 1
        return $object->getData();
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 10
    public function supportsNormalization($data, $format = null)
41
    {
42 10
        return $data instanceof DocumentData;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 1
    public function denormalize($data, $class, $format = null, array $context = array())
49
    {
50 1
        return new DocumentData($data);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 11
    public function supportsDenormalization($data, $type, $format = null)
57
    {
58 11
        return 'Xabbuh\XApi\Model\DocumentData' === $type;
59
    }
60
}
61