PrimaryKeyReferenceNormalizer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsDenormalization() 0 3 1
A normalize() 0 4 1
A supportsNormalization() 0 3 1
A denormalize() 0 3 1
1
<?php
2
3
4
namespace Apie\PrimaryKeyPlugin\Normalizers;
5
6
use Apie\PrimaryKeyPlugin\ValueObjects\PrimaryKeyReference;
7
use LogicException;
8
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
9
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
10
11
/**
12
 * Normalizes PrimaryKeyReference instances. These are used to make references to other api resources.
13
 */
14
class PrimaryKeyReferenceNormalizer implements NormalizerInterface, DenormalizerInterface
15
{
16
    public function denormalize($data, $type, $format = null, array $context = [])
17
    {
18
        throw new LogicException('Not implemented yet');
19
    }
20
21
22
    public function supportsDenormalization($data, $type, $format = null)
23
    {
24
        return $type === PrimaryKeyReference::class;
25
    }
26
27
28
    public function normalize($object, $format = null, array $context = [])
29
    {
30
        /** @var PrimaryKeyReference $object */
31
        return $object->getUrl();
32
    }
33
34
    public function supportsNormalization($data, $format = null)
35
    {
36
        return $data instanceof PrimaryKeyReference;
37
    }
38
}
39