PushoverChannel   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 53
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A send() 0 18 4
A fireFailedEvent() 0 6 1
1
<?php
2
3
namespace NotificationChannels\Pushover;
4
5
use Illuminate\Contracts\Events\Dispatcher;
6
use Illuminate\Notifications\Events\NotificationFailed;
7
use Illuminate\Notifications\Notification;
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 6
    public function __construct(Pushover $pushover, Dispatcher $events)
24
    {
25 6
        $this->pushover = $pushover;
26 6
        $this->events = $events;
27 6
    }
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 6
    public function send($notifiable, Notification $notification)
38
    {
39 6
        if (! $pushoverReceiver = $notifiable->routeNotificationFor('pushover')) {
40 1
            return;
41
        }
42
43 5
        if (is_string($pushoverReceiver)) {
44 2
            $pushoverReceiver = PushoverReceiver::withUserKey($pushoverReceiver);
45
        }
46
47 5
        $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...
48
49
        try {
50 5
            $this->pushover->send(array_merge($message->toArray(), $pushoverReceiver->toArray()));
51 1
        } catch (ServiceCommunicationError $serviceCommunicationError) {
52 1
            $this->fireFailedEvent($notifiable, $notification, $serviceCommunicationError->getMessage());
53
        }
54 5
    }
55
56 1
    protected function fireFailedEvent($notifiable, $notification, $message)
57
    {
58 1
        $this->events->fire(
0 ignored issues
show
Bug introduced by
The method fire() does not seem to exist on object<Illuminate\Contracts\Events\Dispatcher>.

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...
59 1
            new NotificationFailed($notifiable, $notification, 'pushover', [$message])
60
        );
61 1
    }
62
}
63