Completed
Push — feature/VSVGVQ-24 ( 890c4d...a3069c )
by Luc
05:52 queued 02:46
created

UserNormalizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 8 1
A supportsNormalization() 0 3 2
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\User\Serializers;
4
5
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
6
use VSV\GVQ_API\User\Models\User;
7
8
class UserNormalizer implements NormalizerInterface
9
{
10
    /**
11
     * @inheritdoc
12
     * @param User $user
13
     */
14
    public function normalize($user, $format = null, array $context = array())
15
    {
16
        return [
17
            'id' => $user->getId()->toString(),
18
            'email' => $user->getEmail()->toNative(),
19
            'lastName' => $user->getLastName()->toNative(),
20
            'firstName' => $user->getFirstName()->toNative(),
21
            'role' => $user->getRole()->toNative(),
22
        ];
23
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28
    public function supportsNormalization($data, $format = null): bool
29
    {
30
        return ($data instanceof User) && ($format === 'json');
31
    }
32
}
33