| Total Complexity | 4 |
| Total Lines | 28 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 13 | class UserDenormalizer implements DenormalizerInterface |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @inheritdoc |
||
| 17 | */ |
||
| 18 | public function denormalize($data, $class, $format = null, array $context = array()): User |
||
| 19 | { |
||
| 20 | // TODO: Better to use decorator and inject uuid generator. |
||
| 21 | if (!isset($data['id'])) { |
||
| 22 | $data['id'] = Uuid::uuid4(); |
||
| 23 | } |
||
| 24 | |||
| 25 | return new User( |
||
| 26 | Uuid::fromString($data['id']), |
||
| 27 | new Email($data['email']), |
||
| 28 | Password::fromHash($data['password']), |
||
| 29 | new NotEmptyString($data['lastName']), |
||
| 30 | new NotEmptyString($data['firstName']), |
||
| 31 | new Role($data['role']) |
||
| 32 | ); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @inheritdoc |
||
| 37 | */ |
||
| 38 | public function supportsDenormalization($data, $type, $format = null): bool |
||
| 41 | } |
||
| 42 | } |
||
| 43 |