Passed
Push — master ( dd3a40...b9ffdf )
by Hirofumi
07:38
created

SendNotificationHandler::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 8
cts 8
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Notification\Application\Command;
5
6
use Shippinno\Notification\Domain\Model\GatewayRegistry;
7
use Shippinno\Notification\Domain\Model\NotificationId;
8
use Shippinno\Notification\Domain\Model\NotificationNotFoundException;
9
use Shippinno\Notification\Domain\Model\NotificationRepository;
10
11
class SendNotificationHandler
12
{
13
    /**
14
     * @var NotificationRepository
15
     */
16
    private $notificationRepository;
17
18
    /**
19
     * @var GatewayRegistry
20
     */
21
    private $gatewayRegistry;
22
23
    /**
24
     * @param NotificationRepository $notificationRepository
25
     * @param GatewayRegistry $gatewayRegistry
26
     */
27 2
    public function __construct(
28
        NotificationRepository $notificationRepository,
29
        GatewayRegistry $gatewayRegistry
30
    ) {
31 2
        $this->notificationRepository = $notificationRepository;
32 2
        $this->gatewayRegistry = $gatewayRegistry;
33 2
    }
34
35
    /**
36
     * @param SendNotification $command
37
     * @throws NotificationNotFoundException
38
     */
39 2
    public function handle(SendNotification $command): void
40
    {
41 2
        $notificationId = new NotificationId($command->notificationId());
42 2
        $notification = $this->notificationRepository->notificationOfId($notificationId);
43 2
        if (is_null($notification)) {
44 1
            throw new NotificationNotFoundException($notificationId);
45
        }
46 1
        $this->gatewayRegistry->get($notification->destination())->send($notification);
47 1
        $notification->markSent();
48 1
    }
49
}
50