GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f5db3e...2711f4 )
by Mohamed
01:59
created

Channel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 8
Bugs 1 Features 3
Metric Value
wmc 7
c 8
b 1
f 3
lcom 1
cbo 4
dl 0
loc 67
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A interestName() 0 6 1
A send() 0 21 4
A shouldSendMessage() 0 4 1
1
<?php
2
3
namespace NotificationChannels\PusherPushNotifications;
4
5
use NotificationChannels\PusherPushNotifications\Exceptions\CouldNotSendNotification;
6
use NotificationChannels\PusherPushNotifications\Events\MessageWasSent;
7
use NotificationChannels\PusherPushNotifications\Events\SendingMessage;
8
use Illuminate\Notifications\Notification;
9
use Pusher;
10
11
class Channel
12
{
13
    /**
14
     * @var Pusher
15
     */
16
    protected $pusher;
17
18
    public function __construct($pusher)
19
    {
20
        $this->pusher = $pusher;
21
    }
22
23
    /**
24
     * Send the given notification.
25
     *
26
     * @param mixed $notifiable
27
     * @param \Illuminate\Notifications\Notification $notification
28
     *
29
     * @return void
30
     * @throws \NotificationChannels\PusherPushNotifications\Exceptions\CouldNotSendNotification
31
     */
32
    public function send($notifiable, Notification $notification)
33
    {
34
        $interest = $notifiable->routeNotificationFor('PusherPushNotifications')
35
            ?: $this->interestName($notifiable);
36
37
        if (! $this->shouldSendMessage($notifiable, $notification)) {
38
            return;
39
        }
40
41
        $response = $this->pusher->notify(
42
            $interest,
43
            $notification->toPushNotification($notifiable)->toArray(),
44
            true
45
        );
46
47
        if (! in_array($response['status'], [200, 202])) {
48
            throw CouldNotSendNotification::pusherRespondedWithAnError($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->pusher->notify($i...able)->toArray(), true) on line 41 can also be of type boolean; however, NotificationChannels\Pus...rRespondedWithAnError() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
49
        }
50
51
        event(new MessageWasSent($notifiable, $notification));
52
    }
53
54
    /**
55
     * Get the interest name for the notifiable.
56
     *
57
     * @param $notifiable
58
     *
59
     * @return string
60
     */
61
    protected function interestName($notifiable)
62
    {
63
        $class = str_replace('\\', '.', get_class($notifiable));
64
65
        return $class.'.'.$notifiable->getKey();
66
    }
67
68
    /**
69
     * Check if we can send the notification.
70
     *
71
     * @return bool
72
     */
73
    private function shouldSendMessage($notifiable, $notification)
74
    {
75
        return event(new SendingMessage($notifiable, $notification), [], true) !== false;
76
    }
77
}
78