PanaceaMobileChannel::send()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 3
eloc 7
nc 3
nop 2
1
<?php
2
3
namespace NotificationChannels\PanaceaMobile;
4
5
use Illuminate\Notifications\Notification;
6
7
class PanaceaMobileChannel
8
{
9
    /** @var \NotificationChannels\PanaceaMobile\PanaceaMobileApi */
10
    protected $panacea;
11
12
    public function __construct(PanaceaMobileApi $panacea)
13
    {
14
        $this->panacea = $panacea;
15
    }
16
17
    /**
18
     * Send the given notification.
19
     *
20
     * @param  mixed    $notifiable
21
     * @param  \Illuminate\Notifications\Notification  $notification
22
     *
23
     * @throws  \NotificationChannels\PanaceaMobile\Exceptions\CouldNotSendNotification
24
     */
25
    public function send($notifiable, Notification $notification)
26
    {
27
28
        if (! $to = $notifiable->routeNotificationFor('panaceamobile')) {
29
            return;
30
        }
31
32
        $message = $notification->toPanaceaMobile($notifiable);
33
34
        if (is_string($message)) {
35
            $message = new PanaceaMobileMessage($message);
36
        }
37
38
        $this->panacea->send($to, $message->toArray());
39
    }
40
}
41