PrimaryKeyReferenceNormalizer::denormalize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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