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 (#67)
by Dwight
05:50
created

ApnChannel::sendNotification()   A

Complexity

Conditions 3
Paths 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.072

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 8
cts 10
cp 0.8
rs 9.7
c 0
b 0
f 0
cc 3
nc 5
nop 4
crap 3.072
1
<?php
2
3
namespace NotificationChannels\Apn;
4
5
use Illuminate\Notifications\Notification;
6
use Pushok\Client;
7
use Pushok\Notification as PushNotification;
8
9
class ApnChannel
10
{
11
    /**
12
     * The sandbox environment identifier.
13
     *
14
     * @var int
15
     */
16
    const SANDBOX = 0;
17
18
    /**
19
     * The production environment identifier.
20
     *
21
     * @var int
22
     */
23
    const PRODUCTION = 1;
24
25
    /**
26
     * The APNS client.
27
     *
28
     * @var \Pushok\Client
29
     */
30
    protected $client;
31
32
    /**
33
     * Create a new channel instance.
34
     *
35
     * @param  \Pushok\Client  $client
36
     */
37
    public function __construct(Client $client)
38
    {
39
        $this->client = $client;
40
    }
41
42
    /**
43
     * Send the notification to Apple Push Notification Service.
44
     *
45
     * @param mixed $notifiable
46
     * @param \Illuminate\Notifications\Notification $notification
47
     */
48
    public function send($notifiable, Notification $notification)
49
    {
50
        $tokens = (array) $notifiable->routeNotificationFor('apn', $notification);
51
52
        if (empty($tokens)) {
53
            return;
54
        }
55
56
        $message = $notification->toApn($notifiable);
0 ignored issues
show
Bug introduced by
The method toApn() 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...
57
58
        $payload = (new ApnAdapter)->adapt($message);
59
60
        $this->sendNotifications($notifiable, $notification, $tokens, $payload);
0 ignored issues
show
Compatibility introduced by
$notification of type object<Illuminate\Notifications\Notification> is not a sub-type of object<Pushok\Payload>. It seems like you assume a child class of the class Illuminate\Notifications\Notification to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
Unused Code introduced by
The call to ApnChannel::sendNotifications() has too many arguments starting with $tokens.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
61
    }
62
63
    /**
64
     * Send the notification to each of the provided tokens.
65
     *
66
     * @param  array  $tokens
67
     * @param  \Pushok\Payload  $payload
68
     * @return void
69
     */
70
    protected function sendNotifications($tokens, $payload)
71
    {
72
        $notifications = [];
73
74
        foreach ($tokens as $token) {
75
            $notifications[] = new PushNotification($payload, $token);
76
        }
77
78
        $this->client->addNotifications($notifications);
79
80
        $this->client->push();
81
    }
82
}
83