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 ( dc1ae9...58ebf2 )
by David
10s
created

OneSignalChannel::send()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 8.5906
cc 5
eloc 12
nc 5
nop 2
crap 5
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 4
    public function __construct(OneSignalClient $oneSignal)
16
    {
17 4
        $this->oneSignal = $oneSignal;
18 4
    }
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 4
    public function send($notifiable, Notification $notification)
30
    {
31 4
        if (! $userIds = $notifiable->routeNotificationFor('OneSignal')) {
32 1
            return;
33
        }
34
35 3
        $payload = $notification->toOneSignal($notifiable)->toArray();
0 ignored issues
show
Bug introduced by
The method toOneSignal() does not seem to exist on object<Illuminate\Notifications\Notification>.

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.

Loading history...
36
37 3
        if (is_array($userIds) && array_key_exists('email', $userIds)) {
38 1
            $payload['filters'] = collect([['field' => 'email', 'value' => $userIds['email']]]);
39
        } else {
40 2
            $payload['include_player_ids'] = collect($userIds);
41
        }
42
43
        /** @var ResponseInterface $response */
44 3
        $response = $this->oneSignal->sendNotificationCustom($payload);
45
46 3
        if ($response->getStatusCode() !== 200) {
47 1
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
48
        }
49
50 2
        return $response;
51
    }
52
}
53