VodafoneChannel   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 12
c 4
b 0
f 0
dl 0
loc 36
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A send() 0 18 3
1
<?php
2
3
namespace NotificationChannels\Vodafone;
4
5
use Illuminate\Notifications\Notification;
6
use NotificationChannels\Vodafone\Exceptions\CouldNotSendNotification;
7
8
class VodafoneChannel
9
{
10
    /** $var VodafoneClient */
11
    private $client;
12
13
    public function __construct(VodafoneClient $client)
14
    {
15
        $this->client = $client;
16
    }
17
18
    /**
19
     * Send the given notification.
20
     *
21
     * @param mixed $notifiable
22
     * @param Notification $notification
23
     *
24
     * @throws CouldNotSendNotification
25
     */
26
    public function send($notifiable, Notification $notification)
27
    {
28
        /* Confirm the toVodafone method exists before continuing */
29
        if (!method_exists($notification, 'toVodafone')) {
30
            throw CouldNotSendNotification::methodDoesNotExist();
31
        }
32
33
        $message = $notification->toVodafone($notifiable, $notification);
34
35
        /* Check notification uses correct class for this API */
36
        if (!$message instanceof VodafoneMessage) {
37
            throw CouldNotSendNotification::incorrectMessageClass();
38
        }
39
40
        $this->client->send(
41
            $message->from,
42
            $notifiable->routeNotificationFor('vodafone'),
43
            $message->content
44
        );
45
    }
46
}
47