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 ( a4f8bb...56761e )
by Dwight
02:36
created

ApnChannel::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 6
cts 7
cp 0.8571
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.0116
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 1
    public function __construct(Client $client)
38
    {
39 1
        $this->client = $client;
40 1
    }
41
42
    /**
43
     * Send the notification to Apple Push Notification Service.
44
     *
45
     * @param mixed $notifiable
46
     * @param \Illuminate\Notifications\Notification $notification
47
     * @return array|void
48
     */
49 1
    public function send($notifiable, Notification $notification)
50
    {
51 1
        $tokens = (array) $notifiable->routeNotificationFor('apn', $notification);
52
53 1
        if (empty($tokens)) {
54
            return;
55
        }
56
57 1
        $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...
58
59 1
        $payload = (new ApnAdapter)->adapt($message);
60
61 1
        return $this->sendNotifications($tokens, $payload);
62
    }
63
64
    /**
65
     * Send the notification to each of the provided tokens.
66
     *
67
     * @param  array  $tokens
68
     * @param  \Pushok\Payload  $payload
69
     * @return array
70
     */
71 1
    protected function sendNotifications($tokens, $payload)
72
    {
73 1
        $notifications = [];
74
75 1
        foreach ($tokens as $token) {
76 1
            $notifications[] = new PushNotification($payload, $token);
77
        }
78
79 1
        $client = $message->client ?? $this->client;
80
81 1
        $client->addNotifications($notifications);
82
83 1
        return $client->push();
84
    }
85
}
86