Completed
Pull Request — master (#366)
by Beñat
06:07
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\NameConverter\NameConverterInterface;
20
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
21
22
final class SymfonyUserSignedUpNormalizer implements NormalizerInterface
23
{
24
    private $nameConverter;
25
26
    public function __construct(NameConverterInterface $nameConverter)
27
    {
28
        $this->nameConverter = $nameConverter;
29
    }
30
31
    public function normalize($object, $format = null, array $context = []) : array
32
    {
33
        return [
34
            'order'       => $object->order(),
35
            'name'        => $object->name(),
36
            'type'        => $this->nameConverter->normalize(get_class($object->event())),
37
            'occurred_on' => $object->occurredOn()->getTimestamp(),
38
            'payload'     => [
39
                'user_id' => $object->event()->userId()->id(),
40
            ],
41
        ];
42
    }
43
44
    public function supportsNormalization($data, $format = null) : bool
45
    {
46
        return $data instanceof StoredEvent && $data->event() instanceof UserSignedUp;
47
    }
48
}
49