Completed
Pull Request — master (#366)
by Beñat
05:52 queued 01:06
created

LoadNotificationData::type()   A

Complexity

Conditions 1
Paths 1

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 1
eloc 2
nc 1
nop 0
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\Persistence\Doctrine\DataFixtures;
16
17
use Doctrine\Common\Persistence\ObjectManager;
18
use Kreta\Notifier\Application\Command\Inbox\ReadNotificationCommand;
19
use Kreta\Notifier\Application\Command\Inbox\ReceiveNotificationCommand;
20
use Kreta\Notifier\Application\Command\Inbox\UnreadNotificationCommand;
21
use Kreta\SharedKernel\Infrastructure\Persistence\Doctrine\DataFixtures\AbstractFixture;
22
23
class LoadNotificationData extends AbstractFixture
24
{
25
    protected function type() : string
26
    {
27
        return 'notification';
28
    }
29
30
    public function getOrder() : int
31
    {
32
        return 2;
33
    }
34
35
    public function load(ObjectManager $manager) : void
36
    {
37
        $i = 0;
38
        while ($i < $this->amount()) {
39
            $userId = $this->getRandomUserByIndex($i);
40
            $notificationId = $this->fakeIds()[$i];
41
            $body = 'The notification body ' . $i;
42
43
            $receiveNotificationCommand = new ReceiveNotificationCommand($body, $userId, $notificationId);
44
            $this->commandBus()->handle($receiveNotificationCommand);
45
46
            $readNotificationCommand = new ReadNotificationCommand($notificationId, $userId);
47
            $this->commandBus()->handle($readNotificationCommand);
48
49
            if ($i % 2 === 0) {
50
                $unreadNotificationCommand = new UnreadNotificationCommand($notificationId, $userId);
51
                $this->commandBus()->handle($unreadNotificationCommand);
52
            }
53
            ++$i;
54
        }
55
    }
56
}
57