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 (#75)
by
unknown
02:46
created

ApnChannel::storeResponses()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
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
     */
48 1
    public function send($notifiable, Notification $notification)
49
    {
50 1
        $tokens = (array) $notifiable->routeNotificationFor('apn', $notification);
51
52 1
        if (empty($tokens)) {
53
            return;
54
        }
55
56 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...
57
58 1
        $payload = (new ApnAdapter)->adapt($message);
59
60 1
        $responses = $this->sendNotifications($tokens, $payload);
61 1
        $this->storeResponses($notifiable, $responses);
62
    }
63
64
    /**
65
     * Returns an array of ApnsResponseInterfaces from the most recent sending of push notifications.
66
     * @return array
67
     */
68
    public function retrieveResponses(){
69
        return $this->responses;
0 ignored issues
show
Bug introduced by
The property responses does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
70 1
    }
71
72 1
    /**
73
     * Send the notification to each of the provided tokens.
74 1
     *
75 1
     * @param  array  $tokens
76
     * @param  \Pushok\Payload  $payload
77
     * @return void
78 1
     */
79
    protected function sendNotifications($tokens, $payload)
80 1
    {
81 1
        $notifications = [];
82
83
        foreach ($tokens as $token) {
84
            $notifications[] = new PushNotification($payload, $token);
85
        }
86
87
        $this->client->addNotifications($notifications);
88
89
        return $this->client->push();
90
    }
91
92
    /**
93
     * Store the responses from sending the push notification into the notifiable.
94
     *
95
     * @param $notifiable
96
     * @param $responses
97
     */
98
    private function storeResponses($notifiable, $responses)
99
    {
100
        if (method_exists($notifiable, 'storeResponses'))
101
        {
102
            $notifiable->storeResponses($responses);
103
        }
104
    }
105
}
106