Completed
Push — master ( b458df...beeeff )
by Christian
06:18 queued 04:09
created

VerbNormalizer::setSerializer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Xabbuh\XApi\Serializer\Normalizer;
4
5
use Symfony\Component\Serializer\Exception\LogicException;
6
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
7
use Symfony\Component\Serializer\SerializerAwareInterface;
8
use Symfony\Component\Serializer\SerializerInterface;
9
use Xabbuh\XApi\Model\Verb;
10
11
/**
12
 * Denormalizes PHP arrays to {@link Verb} objects.
13
 *
14
 * @author Christian Flothmann <[email protected]>
15
 */
16
final class VerbNormalizer implements DenormalizerInterface, SerializerAwareInterface
17
{
18
    private $serializer;
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 324
    public function setSerializer(SerializerInterface $serializer)
24
    {
25 324
        $this->serializer = $serializer;
26 324
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 37
    public function denormalize($data, $class, $format = null, array $context = array())
32
    {
33 37
        if (!$this->serializer instanceof DenormalizerInterface) {
34
            throw new LogicException('Cannot denormalize because the injected serializer is not a denormalizer.');
35
        }
36
37 37
        $display = null;
38
39 37
        if (isset($data['display'])) {
40 35
            $display = $this->serializer->denormalize($data['display'], 'Xabbuh\XApi\Model\LanguageMap', $format, $context);
41
        }
42
43 37
        return new Verb($data['id'], $display);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 88
    public function supportsDenormalization($data, $type, $format = null)
50
    {
51 88
        return 'Xabbuh\XApi\Model\Verb' === $type;
52
    }
53
}
54