Completed
Push — master ( b2b309...d9443d )
by Casper
06:29 queued 02:05
created

PushoverChannel   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 1 Features 0
Metric Value
wmc 5
c 7
b 1
f 0
lcom 1
cbo 4
dl 0
loc 51
ccs 19
cts 19
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A send() 0 16 3
A fireFailedEvent() 0 6 1
1
<?php
2
3
namespace NotificationChannels\Pushover;
4
5
use Illuminate\Contracts\Events\Dispatcher;
6
use Illuminate\Notifications\Notification;
7
use Illuminate\Notifications\Events\NotificationFailed;
8
use NotificationChannels\Pushover\Exceptions\ServiceCommunicationError;
9
10
class PushoverChannel
11
{
12
    /** @var Pushover */
13
    protected $pushover;
14
15
    /** @var Dispatcher */
16
    protected $events;
17
18
    /**
19
     * Create a new Pushover channel instance.
20
     *
21
     * @param  Pushover $pushover
22
     */
23 4
    public function __construct(Pushover $pushover, Dispatcher $events)
24
    {
25 4
        $this->pushover = $pushover;
26 4
        $this->events = $events;
27 4
    }
28
29
    /**
30
     * Send the given notification.
31
     *
32
     * @param mixed $notifiable
33
     * @param \Illuminate\Notifications\Notification $notification
34
     *
35
     * @throws \NotificationChannels\Pushover\Exceptions\CouldNotSendNotification
36
     */
37 4
    public function send($notifiable, Notification $notification)
38
    {
39 4
        if (! $pushoverKey = $notifiable->routeNotificationFor('pushover')) {
40 1
            return;
41
        }
42
43 3
        $message = $notification->toPushover($notifiable);
0 ignored issues
show
Bug introduced by
The method toPushover() does not seem to exist on object<Illuminate\Notifications\Notification>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
45
        try {
46 3
            $this->pushover->send(array_merge($message->toArray(), [
47 3
                'user' => $pushoverKey,
48 3
            ]));
49 3
        } catch (ServiceCommunicationError $serviceCommunicationError) {
50 1
            $this->fireFailedEvent($notifiable, $notification, $serviceCommunicationError->getMessage());
51
        }
52 3
    }
53
54 1
    protected function fireFailedEvent($notifiable, $notification, $message)
55
    {
56 1
        $this->events->fire(
57 1
            new NotificationFailed($notifiable, $notification, 'pushover', [$message])
58 1
        );
59 1
    }
60
}
61