Test Failed
Push — master ( 6f7a22...abd8b8 )
by Hirofumi
31:24
created

SendNotification   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 32
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 16 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Notification\Domain\Model;
5
6
use InvalidArgumentException;
7
8
class SendNotification
9
{
10
    /**
11
     * @var GatewayRegistry
12
     */
13
    private $gatewayRegistry;
14
15
    /**
16
     * @param GatewayRegistry $gatewayRegistry
17
     */
18
    public function __construct(GatewayRegistry $gatewayRegistry)
19
    {
20
        $this->gatewayRegistry = $gatewayRegistry;
21
    }
22
23
    public function execute(Notification $notification)
24
    {
25
        try {
26
            $gateway = $this->gatewayRegistry->get($notification->destination());
27
        } catch (InvalidArgumentException $e) {
28
            $notification->markFailed('Gateway not found: ' . $e->__toString());
29
30
            return;
31
        }
32
        try {
33
            $gateway->send($notification);
34
            $notification->markSent();
35
        } catch (NotificationNotSentException $e) {
36
            $notification->markFailed('Gateway failed to send: ' . $e->__toString());
37
        }
38
    }
39
}
40