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 | use Minishlink\WebPush\WebPush; |
||
6 | use Illuminate\Notifications\Notification; |
||
7 | use NotificationChannels\WebPush\Events\MessageWasSent; |
||
8 | use NotificationChannels\WebPush\Events\SendingMessage; |
||
9 | |||
10 | class WebPushChannel |
||
11 | { |
||
12 | /** @var \Minishlink\WebPush\WebPush */ |
||
13 | protected $webPush; |
||
14 | |||
15 | /** |
||
16 | * @param \Minishlink\WebPush\WebPush $webPush |
||
17 | * @return void |
||
18 | */ |
||
19 | public function __construct(WebPush $webPush) |
||
20 | { |
||
21 | $this->webPush = $webPush; |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * Send the given notification. |
||
26 | * |
||
27 | * @param mixed $notifiable |
||
28 | * @param \Illuminate\Notifications\Notification $notification |
||
29 | * @return void |
||
30 | */ |
||
31 | public function send($notifiable, Notification $notification) |
||
32 | { |
||
33 | $shouldSendMessage = event(new SendingMessage($notifiable, $notification), [], true) !== false; |
||
34 | |||
35 | if (! $shouldSendMessage) { |
||
36 | return; |
||
37 | } |
||
38 | |||
39 | $subscriptions = $notifiable->routeNotificationFor('WebPush'); |
||
40 | |||
41 | if ($subscriptions->isEmpty()) { |
||
42 | return; |
||
43 | } |
||
44 | |||
45 | $payload = json_encode($notification->toWebPush($notifiable, $notification)->toArray()); |
||
0 ignored issues
–
show
|
|||
46 | |||
47 | $subscriptions->each(function ($sub) use ($payload) { |
||
48 | $this->webPush->sendNotification( |
||
49 | $sub->endpoint, |
||
50 | $payload, |
||
51 | $sub->public_key, |
||
52 | $sub->auth_token |
||
53 | ); |
||
54 | }); |
||
55 | |||
56 | $response = $this->webPush->flush(); |
||
57 | |||
58 | $this->deleteInvalidSubscriptions($response, $subscriptions); |
||
59 | |||
60 | event(new MessageWasSent($notifiable, $notification)); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @param array|bool $response |
||
65 | * @param \Illuminate\Database\Eloquent\Collection $subscriptions |
||
66 | */ |
||
67 | protected function deleteInvalidSubscriptions($response, $subscriptions) |
||
68 | { |
||
69 | if (! is_array($response)) { |
||
70 | return; |
||
71 | } |
||
72 | |||
73 | foreach ($response as $index => $value) { |
||
74 | if (! $value['success'] && isset($subscriptions[$index])) { |
||
75 | $subscriptions[$index]->delete(); |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 |
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.