Normalizer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setSerializer() 0 4 1
A normalizeAttribute() 0 8 2
A denormalizeData() 0 8 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\Symfony\Normalizer;
13
14
use Symfony\Component\Serializer\Exception\LogicException;
15
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
16
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
17
use Symfony\Component\Serializer\SerializerAwareInterface;
18
use Symfony\Component\Serializer\SerializerInterface;
19
20
/**
21
 * @author Christian Flothmann <[email protected]>
22
 */
23
abstract class Normalizer implements DenormalizerInterface, NormalizerInterface, SerializerAwareInterface
24
{
25
    private $serializer;
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function setSerializer(SerializerInterface $serializer)
31
    {
32
        $this->serializer = $serializer;
33
    }
34
35
    protected function normalizeAttribute($value, $format = null, array $context = array())
36
    {
37
        if (!$this->serializer instanceof NormalizerInterface) {
38
            throw new LogicException('Cannot normalize attribute because the injected serializer is not a normalizer');
39
        }
40
41
        return $this->serializer->normalize($value, $format, $context);
42
    }
43
44
    protected function denormalizeData($data, $type, $format = null, array $context = array())
45
    {
46
        if (!$this->serializer instanceof DenormalizerInterface) {
47
            throw new LogicException('Cannot denormalize because the injected serializer is not a denormalizer');
48
        }
49
50
        return $this->serializer->denormalize($data, $type, $format, $context);
51
    }
52
}
53