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

IriNormalizer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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