UuidNormalizer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 26
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A denormalize() 0 3 1
A normalize() 0 3 1
A supportsNormalization() 0 3 1
A supportsDenormalization() 0 3 3
1
<?php
2
namespace Apie\UuidPlugin\Normalizers;
3
4
use Ramsey\Uuid\Uuid;
5
use Ramsey\Uuid\UuidInterface;
6
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
7
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
8
9
class UuidNormalizer implements NormalizerInterface, DenormalizerInterface
10
{
11
    public function denormalize($data, $type, $format = null, array $context = [])
12
    {
13
        return Uuid::fromString($data);
14
    }
15
16
    public function supportsDenormalization($data, $type, $format = null)
17
    {
18
        return (Uuid::class === $type || UuidInterface::class === $type) && is_string($data);
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function normalize($object, $format = null, array $context = array())
25
    {
26
        return $object->toString();
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function supportsNormalization($data, $format = null)
33
    {
34
        return $data instanceof UuidInterface;
35
    }
36
}
37