Completed
Push — master ( 8335a5...efe633 )
by Hilmi Erdem
01:29
created

JetSmsChannel::send()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 18
ccs 10
cts 10
cp 1
rs 9.4285
cc 3
eloc 9
nc 3
nop 2
crap 3
1
<?php
2
3
namespace NotificationChannels\JetSms;
4
5
use Erdemkeren\JetSms\ShortMessage;
6
use Illuminate\Notifications\Notification;
7
use NotificationChannels\JetSms\Exceptions\CouldNotSendNotification;
8
9
/**
10
 * Class JetSmsChannel.
11
 */
12
final class JetSmsChannel
13
{
14
    /**
15
     * Send the given notification.
16
     *
17
     * @param  mixed                                  $notifiable
18
     * @param  \Illuminate\Notifications\Notification $notification
19
     * @throws \NotificationChannels\JetSms\Exceptions\CouldNotSendNotification
20
     * @return void
21
     */
22 3
    public function send($notifiable, Notification $notification)
23
    {
24 3
        $message = $notification->toJetSms($notifiable);
25
26 3
        if ($message instanceof ShortMessage) {
27 1
            JetSms::sendShortMessage($message);
28
29 1
            return;
30
        }
31
32 2
        $to = $notifiable->routeNotificationFor('JetSms');
33
34 2
        if (empty($to)) {
35 1
            throw CouldNotSendNotification::missingRecipient();
36
        }
37
38 1
        JetSms::sendShortMessage($to, $message);
39 1
    }
40
}
41