VodafoneChannel::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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