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

LockAwareSendNotification   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 35
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A execute() 0 11 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