Completed
Pull Request — master (#366)
by Beñat
05:23
created

supportsNormalization()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\Notifier\Infrastructure\Serialization\Inbox;
16
17
use Kreta\Notifier\Domain\Model\Inbox\UserSignedUp;
18
use Kreta\SharedKernel\Event\StoredEvent;
19
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
20
21
final class SymfonyUserSignedUpNormalizer implements NormalizerInterface
22
{
23
    public function normalize($object, $format = null, array $context = []) : array
24
    {
25
        return [
26
            'order'       => $object->order(),
27
            'name'        => $object->name(),
28
            'type'        => get_class($object->event()),
29
            'occurred_on' => $object->occurredOn()->getTimestamp(),
30
            'payload'     => [
31
                'user_id' => $object->event()->userId()->id(),
32
            ],
33
        ];
34
    }
35
36
    public function supportsNormalization($data, $format = null) : bool
37
    {
38
        return $data instanceof StoredEvent && $data->event() instanceof UserSignedUp;
39
    }
40
}
41