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 David
02:13 queued 18s
created

OneSignalChannel   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 8
c 5
b 0
f 1
lcom 1
cbo 4
dl 0
loc 61
ccs 20
cts 20
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B send() 0 29 6
A payload() 0 4 1
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 4
        $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 4
        if (is_array($userIds)) {
38 2
            if (array_key_exists('email', $userIds)) {
39 1
                $payload['filters'] = collect([['field' => 'email', 'value' => $userIds['email']]]);
40 1
            } elseif (array_key_exists('tags', $userIds)) {
41 2
                $payload['tags'] = collect([$userIds['tags']]);
42
            }
43
        } else {
44 2
            $payload['include_player_ids'] = collect($userIds);
45
        }
46
47
        /** @var ResponseInterface $response */
48 4
        $response = $this->oneSignal->sendNotificationCustom(
49 4
            $this->payload($notifiable, $notification, $userIds)
50
        );
51
52 4
        if ($response->getStatusCode() !== 200) {
53 1
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
54
        }
55
56 3
        return $response;
57
    }
58
59
    /**
60
     * @param mixed $notifiable
61
     * @param \Illuminate\Notifications\Notification $notification
62
     * @param mixed $targeting
0 ignored issues
show
Bug introduced by
There is no parameter named $targeting. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
63
     *
64
     * @return array
65
     */
66 4
    protected function payload($notifiable, $notification, $userIds)
67
    {
68 4
        return OneSignalPayloadFactory::make($notifiable, $notification, $userIds);
69
    }
70
}
71