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 ( 1ecb69...1e2954 )
by Freek
02:33
created

OneSignalChannel::send()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.6845
cc 4
eloc 12
nc 4
nop 2
1
<?php
2
3
namespace NotificationChannels\OneSignal;
4
5
use Berkayk\OneSignal\OneSignalClient;
6
use NotificationChannels\OneSignal\Exceptions\CouldNotSendNotification;
7
use NotificationChannels\OneSignal\Events\MessageWasSent;
8
use NotificationChannels\OneSignal\Events\SendingMessage;
9
use Illuminate\Notifications\Notification;
10
use Psr\Http\Message\ResponseInterface;
11
12
class OneSignalChannel
13
{
14
    /** @var OneSignalClient */
15
    protected $oneSignal;
16
17
    public function __construct(OneSignalClient $oneSignal)
18
    {
19
        $this->oneSignal = $oneSignal;
20
    }
21
22
    /**
23
     * Send the given notification.
24
     *
25
     * @param mixed $notifiable
26
     * @param \Illuminate\Notifications\Notification $notification
27
     *
28
     * @throws \NotificationChannels\OneSignal\Exceptions\CouldNotSendNotification
29
     */
30
    public function send($notifiable, Notification $notification)
31
    {
32
        if (! $userIds = $notifiable->routeNotificationFor('OneSignal')) {
33
            return;
34
        }
35
36
        $shouldSendMessage = event(new SendingMessage($notifiable, $notification), [], true) !== false;
37
38
        if (! $shouldSendMessage) {
39
            return;
40
        }
41
42
        $payload = $notification->toOneSignal($notifiable)->toArray();
43
        $payload['include_player_ids'] = collect($userIds);
44
45
        /** @var ResponseInterface $response */
46
        $response = $this->oneSignal->sendNotificationCustom($payload);
47
48
        if ($response->getStatusCode() !== 200) {
49
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
50
        }
51
52
        event(new MessageWasSent($notifiable, $notification));
53
    }
54
}
55