Completed
Pull Request — master (#366)
by Beñat
04:43 queued 26s
created

normalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 3
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\Notification;
16
17
use Kreta\Notifier\Domain\Model\Inbox\Notification\NotificationMarkedAsRead;
18
use Kreta\SharedKernel\Event\StoredEvent;
19
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
20
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
21
22 View Code Duplication
final class SymfonyNotificationMarkedAsReadNormalizer implements NormalizerInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
                'id'      => $object->event()->notificationId()->id(),
40
                'user_id' => $object->event()->userId()->id(),
41
                'status'  => $object->event()->status()->status(),
42
            ],
43
        ];
44
    }
45
46
    public function supportsNormalization($data, $format = null) : bool
47
    {
48
        return $data instanceof StoredEvent && $data->event() instanceof NotificationMarkedAsRead;
49
    }
50
}
51