UserNormalizer::normalize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
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
            'language' => $user->getLanguage()->toNative(),
23
        ];
24
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function supportsNormalization($data, $format = null): bool
30
    {
31
        return ($data instanceof User) && ($format === 'json');
32
    }
33
}
34