Completed
Push — master ( f96e3c...dc495a )
by Casper
09:34 queued 01:13
created

PushoverChannel   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 5
c 6
b 1
f 0
lcom 1
cbo 3
dl 0
loc 48
ccs 23
cts 23
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\Notifications\Notification;
6
use Illuminate\Notifications\Events\NotificationFailed;
7
use Illuminate\Contracts\Events\Dispatcher;
8
use NotificationChannels\Pushover\Exceptions\ServiceCommunicationError;
9
10
class PushoverChannel
11
{
12
    /** @var Pushover */
13
    protected $pushover;
14
15
    /**
16
     * Create a new Pushover channel instance.
17
     *
18
     * @param  Pushover $pushover
19
     */
20 4
    public function __construct(Pushover $pushover, Dispatcher $events)
21
    {
22 4
        $this->pushover = $pushover;
23 4
        $this->events = $events;
0 ignored issues
show
Bug introduced by
The property events does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24 4
    }
25
26
    /**
27
     * Send the given notification.
28
     *
29
     * @param mixed $notifiable
30
     * @param \Illuminate\Notifications\Notification $notification
31
     *
32
     * @throws \NotificationChannels\Pushover\Exceptions\CouldNotSendNotification
33
     */
34 4
    public function send($notifiable, Notification $notification)
35
    {
36 4
        if (! $pushoverKey = $notifiable->routeNotificationFor('pushover')) {
37 1
            return;
38
        }
39
40 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...
41
42
        try {
43 3
            $this->pushover->send(array_merge($message->toArray(), [
44 3
                'user' => $pushoverKey,
45 3
            ]));
46 3
        } catch (ServiceCommunicationError $serviceCommunicationError) {
47 3
            $this->fireFailedEvent($notifiable, $notification, $serviceCommunicationError->getMessage());
48 3
        }
49 3
    }
50 3
51 3
    protected function fireFailedEvent($notifiable, $notification, $message)
52 3
    {
53 3
        $this->events->fire(
54 3
            new NotificationFailed($notifiable, $notification, 'pushover', [$message])
55 3
        );
56 1
    }
57
}
58