Passed
Push — feature/VSVGVQ-20 ( 74a99d...9a1232 )
by steven
04:33
created

UserDenormalizer::supportsDenormalization()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 2
eloc 1
nc 2
nop 3
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\User\Serializers;
4
5
use Ramsey\Uuid\Uuid;
6
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
7
use VSV\GVQ_API\Common\ValueObjects\NotEmptyString;
8
use VSV\GVQ_API\User\Models\User;
9
use VSV\GVQ_API\User\ValueObjects\Email;
10
use VSV\GVQ_API\User\ValueObjects\Password;
11
use VSV\GVQ_API\User\ValueObjects\Role;
12
13
class UserDenormalizer implements DenormalizerInterface
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function denormalize($data, $class, $format = null, array $context = array()): User
19
    {
20
        return new User(
21
            Uuid::fromString($data['id']),
22
            new Email($data['email']),
23
            Password::fromHash($data['password']),
24
            new NotEmptyString($data['lastName']),
25
            new NotEmptyString($data['firstName']),
26
            new Role($data['role'])
27
        );
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function supportsDenormalization($data, $type, $format = null): bool
34
    {
35
        return ($type === User::class) && ($format === 'json');
36
    }
37
}
38