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
Pull Request — master (#26)
by Hanlin
03:05
created

PusherChannel   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 61
ccs 0
cts 25
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A interestName() 0 6 1
A send() 0 17 3
1
<?php
2
3
namespace NotificationChannels\PusherPushNotifications;
4
5
use Pusher;
6
use Illuminate\Events\Dispatcher;
7
use Illuminate\Notifications\Notification;
8
use Illuminate\Notifications\Events\NotificationFailed;
9
10
class PusherChannel
11
{
12
    /**
13
     * @var \Pusher
14
     */
15
    protected $pusher;
16
17
    /**
18
     * @var \Illuminate\Events\Dispatcher
19
     */
20
    private $events;
21
22
    /**
23
     * @param \Pusher $pusher
24
     */
25
    public function __construct(Pusher $pusher, Dispatcher $events)
26
    {
27
        $this->pusher = $pusher;
28
        $this->events = $events;
29
    }
30
31
    /**
32
     * Send the given notification.
33
     *
34
     * @param mixed $notifiable
35
     * @param \Illuminate\Notifications\Notification $notification
36
     *
37
     * @return void
38
     */
39
    public function send($notifiable, Notification $notification)
40
    {
41
        $interest = $notifiable->routeNotificationFor('PusherPushNotifications')
42
            ?: $this->interestName($notifiable);
43
44
        $response = $this->pusher->notify(
45
            $interest,
46
            $notification->toPushNotification($notifiable)->toArray(),
0 ignored issues
show
Bug introduced by
The method toPushNotification() 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...
47
            true
48
        );
49
50
        if (! in_array($response['status'], [200, 202])) {
51
            $this->events->fire(
52
                new NotificationFailed($notifiable, $notification, 'pusher-push-notifications', $response)
0 ignored issues
show
Bug introduced by
It seems like $response defined by $this->pusher->notify($i...able)->toArray(), true) on line 44 can also be of type boolean; however, Illuminate\Notifications...onFailed::__construct() 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...
53
            );
54
        }
55
    }
56
57
    /**
58
     * Get the interest name for the notifiable.
59
     *
60
     * @param $notifiable
61
     *
62
     * @return string
63
     */
64
    protected function interestName($notifiable)
65
    {
66
        $class = str_replace('\\', '.', get_class($notifiable));
67
68
        return $class.'.'.$notifiable->getKey();
69
    }
70
}
71