HooksChannel::send()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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