Passed
Push — master ( 79f40f...37a828 )
by Hirofumi
02:31
created

LockAwareSendNotification::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 9
cts 9
cp 1
rs 9.9
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\Domain\Model;
5
6
class LockAwareSendNotification extends SendNotification
7
{
8
    /**
9
     * @var NotificationRepository
10
     */
11
    private $notificationRepository;
12
13
    /**
14
     * @param GatewayRegistry $gatewayRegistry
15
     * @param NotificationRepository $notificationRepository
16
     */
17 2
    public function __construct(
18
        GatewayRegistry $gatewayRegistry,
19
        NotificationRepository $notificationRepository
20
    ) {
21 2
        parent::__construct($gatewayRegistry);
22 2
        $this->notificationRepository = $notificationRepository;
23 2
    }
24
25
    /**
26
     * {@inheritdoc}
27
     * @throws NotificationLockedException
28
     */
29 2
    public function execute(Notification $notification): void
30
    {
31 2
        if ($notification->isLocked()) {
32 1
            throw new NotificationLockedException($notification);
33
        }
34 1
        $notification->lock();
35 1
        $this->notificationRepository->persist($notification);
36 1
        parent::execute($notification);
37 1
        $notification->unlock();
38 1
        $this->notificationRepository->persist($notification);
39 1
    }
40
}
41