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
|
|||
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
|
|||
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 |
This check looks for function calls that miss required arguments.