Completed
Pull Request — master (#21)
by Christian
03:19
created

IrlNormalizer::normalize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 3
cts 3
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
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 Xabbuh\XApi\Model\IRL;
15
16
/**
17
 * Normalizes and denormalizes internationalized resource locators.
18
 *
19
 * @author Christian Flothmann <[email protected]>
20
 */
21
final class IrlNormalizer extends Normalizer
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26 18
    public function normalize($object, $format = null, array $context = array())
27
    {
28 18
        if (!$object instanceof IRL) {
29
            return;
30
        }
31
32 18
        return $object->getValue();
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 128
    public function supportsNormalization($data, $format = null)
39
    {
40 128
        return $data instanceof IRL;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 2
    public function denormalize($data, $class, $format = null, array $context = array())
47
    {
48 2
        return IRL::fromString($data);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 122
    public function supportsDenormalization($data, $type, $format = null)
55
    {
56 122
        return 'Xabbuh\XApi\Model\IRL' === $type;
57
    }
58
}
59