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 (#27)
by Hanlin
03:13
created

PusherChannel::interestName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace NotificationChannels\PusherPushNotifications;
4
5
use Illuminate\Events\Dispatcher;
6
use Illuminate\Notifications\Notification;
7
use Illuminate\Notifications\Events\NotificationFailed;
8
use Pusher\PushNotifications\PushNotifications;
9
10
class PusherChannel
11
{
12
    /**
13
     * @var \Pusher\PushNotifications\PushNotifications $pusher
14
     */
15
    protected $pusher;
16
17
    /**
18
     * @var \Illuminate\Events\Dispatcher
19
     */
20
    private $events;
21
22
    /**
23
     * @param \Pusher\PushNotifications\PushNotifications $pusher
24
     * @param \Illuminate\Events\Dispatcher
25
     */
26 2
    public function __construct(PushNotifications $pusher, Dispatcher $events)
27
    {
28 2
        $this->pusher = $pusher;
29 2
        $this->events = $events;
30 2
    }
31
32
    /**
33
     * Send the given notification.
34
     *
35
     * @param mixed $notifiable
36
     * @param \Illuminate\Notifications\Notification $notification
37
     *
38
     * @return void
39
     */
40 2
    public function send($notifiable, Notification $notification)
41
    {
42 2
        $interest = $notifiable->routeNotificationFor('PusherPushNotifications')
43 2
            ?: $this->interestName($notifiable);
44
        
45 2
        if(is_string($interest)) {
46 2
            $interest = [$interest];
47
        }
48
49
        try {
50 2
            $response = $this->pusher->publish(
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
51 2
                $interest,
52 2
                $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...
53
            );
54 1
        }catch (\Exception $e) {
55 1
            $this->events->fire(
56 1
                new NotificationFailed($notifiable, $notification, 'pusher-push-notifications')
57
            );
58
        }
59 2
    }
60
61
    /**
62
     * Get the interest name for the notifiable.
63
     *
64
     * @param $notifiable
65
     *
66
     * @return string
67
     */
68
    protected function interestName($notifiable)
69
    {
70
        $class = str_replace('\\', '.', get_class($notifiable));
71
72
        return $class.'.'.$notifiable->getKey();
73
    }
74
}
75