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 (#66)
by
unknown
04:48
created

ApnSendTestNotification::optionsAreInvalid()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
3
namespace NotificationChannels\Apn\Console;
4
5
use Notification;
6
use Illuminate\Console\Command;
7
use NotificationChannels\Apn\Notifications\ApnTestNotification;
8
9
class ApnSendTestNotification extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'apn:test 
17
                            {--T|token= : The token of the device that the PN will be sent to.} 
18
                            {--t|title=Test APN Notification : The title of the PN.} 
19
                            {--m|message=This is a test push notification sent from the console. : The message body for the PN.} 
20
                            {--b|badge=1 : The number that will be displayed in the app\'s badge notification.}
21
                            {--s|sound=default : The name of the sound that should be played with the notification.}';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Send a test push notification using the APN service.';
29
30
    /**
31
     * Execute the console command.
32
     *
33
     * @return void
34
     */
35
    public function handle(): void
36
    {
37
        if ($errors = $this->optionsAreInvalid()) {
38
            foreach ($errors as $error) {
39
                $this->error($error);
40
            }
41
            return;
42
        }
43
44
        $this->sendNotification();
45
        $this->info('Push notification sent.');
46
    }
47
48
    /**
49
     * Validate whether if the options passed in the command
50
     * are valid. An array of errors is returned if any
51
     * options fail the checks. Null is returned if
52
     * the options are all valid.
53
     *
54
     * @param array $errors
55
     * @return array|null
56
     */
57
    private function optionsAreInvalid(array $errors = [])
58
    {
59
        if (!$this->option('token')) {
60
            $errors[] = 'No device token (--token) is specified.';
61
        }
62
63
        if ($this->option('badge') != '0' && !(int)$this->option('badge')) {
64
            $errors[] = 'The badge number (--badge) must be an integer.';
65
        }
66
67
        return $errors ?? null;
68
    }
69
70
    /**
71
     * Trigger the notification to send to the testing device.
72
     *
73
     * @return void
74
     */
75
    private function sendNotification()
76
    {
77
        Notification::route('apn', $this->option('token'))
78
            ->notify(new APNTestNotification($this->option('title'), $this->option('message'), (int)$this->option('badge'), $this->option('sound')));
79
    }
80
}