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 ( 7e6ebb...3066b8 )
by Dwight
12s
created

ApnChannel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 91.43%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 8
dl 0
loc 96
ccs 32
cts 35
cp 0.9143
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B send() 0 46 6
A __construct() 0 6 1
1
<?php
2
3
namespace NotificationChannels\Apn;
4
5
use Exception;
6
use Illuminate\Events\Dispatcher;
7
use ZendService\Apple\Apns\Message\Alert;
8
use Illuminate\Notifications\Notification;
9
use ZendService\Apple\Apns\Message as Packet;
10
use ZendService\Apple\Apns\Client\Message as Client;
11
use NotificationChannels\Apn\Exceptions\SendingFailed;
12
use Illuminate\Notifications\Events\NotificationFailed;
13
use ZendService\Apple\Apns\Response\Message as Response;
14
15
class ApnChannel
16
{
17
    use InteractsWithConnection;
18
19
    /**
20
     * The sandbox environment identifier.
21
     *
22
     * @var int
23
     */
24
    const SANDBOX = 0;
25
26
    /**
27
     * The production environment identifier.
28
     *
29
     * @var int
30
     */
31
    const PRODUCTION = 1;
32
33
    /** @var \ZendService\Apple\Apns\Client\Message */
34
    protected $client;
35
36
    /** @var \Illuminate\Events\Dispatcher */
37
    protected $events;
38
39
    /** @var \NotificationChannels\Apn\ApnCredentials */
40
    protected $credentials;
41
42
    /**
43
     * Create a new instance of the APN channel.
44
     *
45
     * @param  \ZendService\Apple\Apns\Client\Message  $client
46
     * @param  \Illuminate\Events\Dispatcher  $events
47
     * @param  \NotificationChannels\Apn\ApnCredentials  $credentials
48
     */
49 2
    public function __construct(Client $client, Dispatcher $events, ApnCredentials $credentials)
50
    {
51 2
        $this->client = $client;
52 2
        $this->events = $events;
53 2
        $this->credentials = $credentials;
54 2
    }
55
56
    /**
57
     * Send the notification to Apple Push Notification Service.
58
     *
59
     * @param mixed $notifiable
60
     * @param \Illuminate\Notifications\Notification $notification
61
     *
62
     * @throws \NotificationChannels\Apn\Exceptions\SendingFailed
63
     */
64 2
    public function send($notifiable, Notification $notification)
65
    {
66 2
        $tokens = (array) $notifiable->routeNotificationFor('apn');
67 2
        if (empty($tokens)) {
68
            return;
69
        }
70
71 2
        $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...
72 2
        if (! $message) {
73
            return;
74
        }
75
76 2
        $this->openConnection();
77
78 2
        foreach ($tokens as $token) {
79
            try {
80 2
                $alert = new Alert();
81 2
                $alert->setTitle($message->title);
82 2
                $alert->setBody($message->body);
83
84 2
                $packet = new Packet();
85 2
                $packet->setToken($token);
86 2
                $packet->setBadge($message->badge);
87 2
                $packet->setSound($message->sound);
88 2
                $packet->setCategory($message->category);
89 2
                $packet->setContentAvailable($message->contentAvailable);
90 2
                $packet->setAlert($alert);
91 2
                $packet->setCustom($message->custom);
92
93 2
                $response = $this->client->send($packet);
94
95 2
                if ($response->getCode() !== Response::RESULT_OK) {
96 1
                    $this->events->fire(
97 1
                        new NotificationFailed($notifiable, $notification, $this, [
0 ignored issues
show
Documentation introduced by
$this is of type this<NotificationChannels\Apn\ApnChannel>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
98 1
                            'token' => $token,
99 2
                            'error' => $response->getCode(),
100
                        ])
101
                    );
102
                }
103
            } catch (Exception $e) {
104 2
                throw SendingFailed::create($e);
105
            }
106
        }
107
108 2
        $this->closeConnection();
109 2
    }
110
}
111