HooksChannel   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 14 3
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