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 ( cdb1b9...55c78e )
by Cretu
09:06
created

src/HasPushSubscriptions.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace NotificationChannels\WebPush;
4
5
trait HasPushSubscriptions
6
{
7
    /**
8
     * Get the user's push subscriptions.
9
     *
10
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
11
     */
12
    public function pushSubscriptions()
13
    {
14
        return $this->hasMany(PushSubscription::class);
15
    }
16
17
    /**
18
     * Update (or create) user subscription.
19
     *
20
     * @param  string $endpoint
21
     * @param  string|null $key
22
     * @param  string|null $token
23
     *
24
     * @return PushSubscription
25
     */
26
    public function updatePushSubscription($endpoint, $key = null, $token = null)
27
    {
28
        $subscription = PushSubscription::findByEndpoint($endpoint);
29
30
        if ($subscription && ! $this->subscriptionBelongsToDifferentUser()) {
0 ignored issues
show
The call to subscriptionBelongsToDifferentUser() misses a required argument $subscription.

This check looks for function calls that miss required arguments.

Loading history...
31
            $subscription->public_key = $key;
32
            $subscription->auth_token = $token;
33
            $subscription->save();
34
35
            return $subscription;
36
        }
37
38
        if ($subscription && $this->subscriptionBelongsToDifferentUser()) {
0 ignored issues
show
The call to subscriptionBelongsToDifferentUser() misses a required argument $subscription.

This check looks for function calls that miss required arguments.

Loading history...
39
            $subscription->delete();
40
        }
41
42
43
        return $this->pushSubscriptions()->save(new PushSubscription([
44
            'endpoint' => $endpoint,
45
            'public_key' => $key,
46
            'auth_token' => $token,
47
        ]));
48
    }
49
50
    /**
51
     * @param PushSubscription $subscription
52
     * @return bool
53
     */
54
    public function subscriptionBelongsToDifferentUser($subscription)
55
    {
56
        return (int) $subscription->user_id !== (int) $this->getAuthIdentifier();
57
    }
58
59
    /**
60
     * Delete subscription by endpoint.
61
     *
62
     * @param  string $endpoint
63
     * @return void
64
     */
65
    public function deleteSubscription($endpoint)
66
    {
67
        $this->pushSubscriptions()
68
            ->where('endpoint', $endpoint)
69
            ->delete();
70
    }
71
72
    /**
73
     * Get all subscriptions.
74
     *
75
     * @return \Illuminate\Database\Eloquent\Collection
76
     */
77
    public function routeNotificationForWebPush()
78
    {
79
        return $this->pushSubscriptions;
80
    }
81
}
82