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.

GcmNotification::getPayload()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.2
c 0
b 0
f 0
cc 4
eloc 12
nc 6
nop 0
1
<?php
2
3
namespace Openpp\NotificationHubsRest\Notification;
4
5
class GcmNotification extends AbstractNotification
6
{
7
    /**
8
     * @var string[]
9
     */
10
    private $supportedOptions = [
11
        'collapse_key',
12
        'delay_while_idle',
13
        'time_to_live',
14
        'restricted_package_name',
15
        'dry_run',
16
    ];
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function getFormat()
22
    {
23
        return 'gcm';
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function getContentType()
30
    {
31
        return 'application/json;charset=utf-8';
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getPayload()
38
    {
39
        if (!empty($this->options)) {
40
            $payload = array_intersect_key($this->options, array_fill_keys($this->supportedOptions, 0));
41
        } else {
42
            $payload = [];
43
        }
44
45
        if (is_array($this->alert)) {
46
            $payload += ['data' => $this->alert];
47
        } elseif (is_scalar($this->alert)) {
48
            $payload += ['data' => ['message' => $this->alert]];
49
        } else {
50
            throw new \RuntimeException('Invalid alert.');
51
        }
52
53
        return json_encode($payload);
54
    }
55
}
56