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   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B send() 0 24 4
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