Passed
Push — master ( bbba98...76b67c )
by Farhad
04:30
created

RayganSmsChannel::shouldSendMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace NotificationChannels\RayganSms;
4
5
use DomainException;
6
use Illuminate\Notifications\Notification;
7
use NotificationChannels\RayganSms\Events\MessageWasSent;
8
use NotificationChannels\RayganSms\Events\SendingMessage;
9
use NotificationChannels\RayganSms\Exceptions\CouldNotSendNotification;
10
use Trez\RayganSms\Facades\RayganSms;
11
12
class RayganSmsChannel
13
{
14
    public function __construct()
15
    {
16
    }
17
18
    /**
19
     * Send the given notification.
20
     *
21
     * @param mixed        $notifiable
22
     * @param Notification $notification
23
     *
24
     * @return void
25
     */
26
    public function send($notifiable, Notification $notification)
27
    {
28
29
        if (!$to = $notifiable->routeNotificationFor('raygansms')) {
30
            return;
31
        }
32
33
        $message = $notification->{'toRayganSms'}($notifiable);
34
35
        if (is_string($message)) {
36
            $message = new RayganSmsMessage($message);
37
        }
38
39
        try {
40
            RayganSms::sendMessage($to, $message->getContent());
41
        } catch (DomainException $e) {
42
            throw CouldNotSendNotification::serviceRespondedWithAnError($e);
43
        }
44
    }
45
}
46