FortySixElksChannel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 15 4
A __construct() 0 3 1
1
<?php
2
3
namespace NotificationChannels\FortySixElks;
4
5
use Illuminate\Events\Dispatcher;
6
use Illuminate\Notifications\Events\NotificationFailed;
7
use Illuminate\Notifications\Notification;
8
use NotificationChannels\FortySixElks\Exceptions\CouldNotUseNotification;
9
10
class FortySixElksChannel
11
{
12
    protected $events;
13
14
    /**
15
     * FortySixElksChannel constructor.
16
     */
17
    public function __construct(Dispatcher $events)
18
    {
19
        $this->events = $events;
20
    }
21
22
    /**
23
     * Send the given notification.
24
     *
25
     * @param mixed                                  $notifiable
26
     * @param \Illuminate\Notifications\Notification $notification
27
     *
28
     * @throws \NotificationChannels\FortySixElks\Exceptions\CouldNotSendNotification
29
     */
30
    public function send($notifiable, Notification $notification)
31
    {
32
        if (method_exists($notification, 'to46Elks')) {
33
            if ($media = $notification->to46Elks($notifiable)) {
34
                try {
35
                    return $media->send();
36
                } catch (\Exception $e) {
37
                    $this->events->dispatch(new NotificationFailed($notifiable, $notification, get_class($this), ['exception' => $e]));
38
                }
39
            }
40
        } else {
41
            throw CouldNotUseNotification::missingMethod();
42
        }
43
44
        return false;
45
    }
46
}
47