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

LockAwareSendNotification::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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