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

UuidNormalizer::denormalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 4
dl 0
loc 3
rs 10
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