RayganSmsChannel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A send() 0 16 4
1
<?php
2
3
namespace NotificationChannels\RayganSms;
4
5
use DomainException;
6
use Illuminate\Notifications\Notification;
7
use NotificationChannels\RayganSms\Exceptions\CouldNotSendNotification;
8
use Trez\RayganSms\Facades\RayganSms;
9
10
class RayganSmsChannel
11
{
12
    public function __construct()
13
    {
14
    }
15
16
    /**
17
     * Send the given notification.
18
     *
19
     * @param mixed        $notifiable
20
     * @param Notification $notification
21
     *
22
     * @return void
23
     */
24
    public function send($notifiable, Notification $notification)
25
    {
26
        if (!$to = $notifiable->routeNotificationFor('raygansms')) {
27
            return;
28
        }
29
30
        $message = $notification->{'toRayganSms'}($notifiable);
31
32
        try {
33
            if ($message->type == 'txt') {
34
                RayganSms::sendMessage($to, $message->content);
35
            } else {
36
                RayganSms::sendAuthCode($to, $message->content, $message->autoGenerate);
37
            }
38
        } catch (DomainException $e) {
39
            throw CouldNotSendNotification::serviceRespondedWithAnError($e);
40
        }
41
    }
42
}
43