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
Pull Request — master (#50)
by Tim
02:02
created

OneSignalChannel::send()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

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