Completed
Push — master ( 8865c9...169b65 )
by Christian
03:22
created

AccountNormalizer::denormalize()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 8
nc 4
nop 4
crap 3
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 Xabbuh\XApi\Model\Account;
15
use Xabbuh\XApi\Model\IRL;
16
17
/**
18
 * Normalizes and denormalizes xAPI statement accounts.
19
 *
20
 * @author Christian Flothmann <[email protected]>
21
 */
22
final class AccountNormalizer extends Normalizer
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 15
    public function normalize($object, $format = null, array $context = array())
28
    {
29 15
        if (!$object instanceof Account) {
30
            return null;
31
        }
32
33
        return array(
34 15
            'name' => $object->getName(),
35 15
            'homePage' => $object->getHomePage()->getValue(),
0 ignored issues
show
Bug introduced by
The method getValue cannot be called on $object->getHomePage() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
36
        );
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 179
    public function supportsNormalization($data, $format = null)
43
    {
44 179
        return $data instanceof Account;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 17
    public function denormalize($data, $class, $format = null, array $context = array())
51
    {
52 17
        $name = '';
53 17
        $homePage = '';
54
55 17
        if (isset($data['name'])) {
56 17
            $name = $data['name'];
57
        }
58
59 17
        if (isset($data['homePage'])) {
60 17
            $homePage = $data['homePage'];
61
        }
62
63 17
        return new Account($name, IRL::fromString($homePage));
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 189
    public function supportsDenormalization($data, $type, $format = null)
70
    {
71 189
        return 'Xabbuh\XApi\Model\Account' === $type;
72
    }
73
}
74