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

VerbNormalizer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 53
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 16 3
A supportsNormalization() 0 4 1
A denormalize() 0 11 2
A supportsDenormalization() 0 4 1
1
<?php
2
3
namespace Xabbuh\XApi\Serializer\Normalizer;
4
5
use Xabbuh\XApi\Model\IRI;
6
use Xabbuh\XApi\Model\Verb;
7
8
/**
9
 * Denormalizes PHP arrays to {@link Verb} objects.
10
 *
11
 * @author Christian Flothmann <[email protected]>
12
 */
13
final class VerbNormalizer extends Normalizer
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 40
    public function normalize($object, $format = null, array $context = array())
19
    {
20 40
        if (!$object instanceof Verb) {
21
            return;
22
        }
23
24
        $data = array(
25 40
            'id' => $object->getId()->getValue(),
0 ignored issues
show
Bug introduced by
The method getValue cannot be called on $object->getId() (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...
26
        );
27
28 40
        if (null !== $display = $object->getDisplay()) {
29 38
            $data['display'] = $this->normalizeAttribute($display, $format, $context);
30
        }
31
32 40
        return $data;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 85
    public function supportsNormalization($data, $format = null)
39
    {
40 85
        return $data instanceof Verb;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 42
    public function denormalize($data, $class, $format = null, array $context = array())
47
    {
48 42
        $id = IRI::fromString($data['id']);
49 42
        $display = null;
50
51 42
        if (isset($data['display'])) {
52 40
            $display = $this->denormalizeData($data['display'], 'Xabbuh\XApi\Model\LanguageMap', $format, $context);
53
        }
54
55 42
        return new Verb($id, $display);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 87
    public function supportsDenormalization($data, $type, $format = null)
62
    {
63 87
        return 'Xabbuh\XApi\Model\Verb' === $type;
64
    }
65
}
66