ZonerSmsGatewayChannel   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.12%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 54
ccs 16
cts 17
cp 0.9412
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
C send() 0 32 8
1
<?php
2
3
namespace NotificationChannels\ZonerSmsGateway;
4
5
use Illuminate\Notifications\Notification;
6
use NotificationChannels\ZonerSmsGateway\Exceptions\ZonerSmsGatewayException;
7
8
class ZonerSmsGatewayChannel
9
{
10
    /**
11
     * @var ZonerSmsGateway
12
     */
13
    protected $gateway;
14
15 11
    public function __construct(ZonerSmsGateway $gateway)
16
    {
17 11
        $this->gateway = $gateway;
18 11
    }
19
20
    /**
21
     * Send the given notification.
22
     *
23
     * @param mixed $notifiable
24
     * @param Notification $notification
25
     *
26
     * @return tracking number
27
     * @throws ZonerSmsGatewayException
28
     */
29 11
    public function send($notifiable, Notification $notification)
30
    {
31 11
        $message = $notification->toZonerSmsGateway($notifiable);
32
33 11
        if (is_string($message)) {
34
            $message = new ZonerSmsGatewayMessage($message);
35
        }
36
37
        // Use the receiver from message, if defined:
38 11
        $receiver = $message->receiver;
39
40
        // Otherwise use the receiver given by notifiable routeNotificationForZonerSmsGateway:
41 11
        if (empty($receiver) && method_exists($notifiable, 'routeNotificationForZonerSmsGateway')) {
42 8
            $receiver = $notifiable->routeNotificationForZonerSmsGateway();
43
        }
44
45
        // Otherwise use the receiver given by notifiable generic routing method:
46 11
        if (empty($receiver)) {
47 2
            $receiver = $notifiable->routeNotificationFor(self::class);
48
        }
49
50
        // As the last resort, try to get the phone_number attribute from notifiable:
51 11
        if (empty($receiver) && isset($notifiable->phone_number)) {
52 1
            $receiver = $notifiable->phone_number;
53
        }
54
55 11
        if (empty($receiver)) {
56 1
            return; // Give up
57
        }
58
59 10
        return $this->gateway->sendMessage($receiver, trim($message->content), $message->sender);
60
    }
61
}
62