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

AccountNormalizer::supportsDenormalization()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 3
crap 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\Account;
17
18
/**
19
 * @author Christian Flothmann <[email protected]>
20
 */
21
final class AccountNormalizer implements DenormalizerInterface, NormalizerInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function normalize($object, $format = null, array $context = array())
27
    {
28
        if (!$object instanceof Account) {
29
            return null;
30
        }
31
32
        return array(
33
            'name' => $object->getName(),
34
            'homePage' => $object->getHomePage(),
35
        );
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function supportsNormalization($data, $format = null)
42
    {
43
        return $data instanceof Account;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function denormalize($data, $class, $format = null, array $context = array())
50
    {
51
        $name = '';
52
        $homePage = '';
53
54
        if (isset($data['name'])) {
55
            $name = $data['name'];
56
        }
57
58
        if (isset($data['homePage'])) {
59
            $homePage = $data['homePage'];
60
        }
61
62
        return new Account($name, $homePage);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function supportsDenormalization($data, $type, $format = null)
69
    {
70
        return 'Xabbuh\XApi\Model\Account' === $type;
71
    }
72
}
73