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

SendNotification::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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