Passed
Branch 3.0.0 (3c68a7)
by Pieter
04:04
created

UuidNormalizer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsNormalization() 0 3 1
A normalize() 0 3 1
A supportsDenormalization() 0 3 3
A denormalize() 0 3 1
1
<?php
2
namespace W2w\Lib\Apie\Plugins\Uuid\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