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.

AppleNotification::getPayload()   C
last analyzed

Complexity

Conditions 7
Paths 15

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 19
nc 15
nop 0
1
<?php
2
3
namespace Openpp\NotificationHubsRest\Notification;
4
5
class AppleNotification extends AbstractNotification
6
{
7
    /**
8
     * @var string[]
9
     */
10
    private $supportedOptions = [
11
        'badge',
12
        'sound',
13
        'content-available',
14
    ];
15
16
    /**
17
     * @var string[]
18
     */
19
    private $supportedAlertProperties = [
20
        'title',
21
        'body',
22
        'title-loc-key',
23
        'title-loc-args',
24
        'action-loc-key',
25
        'loc-key',
26
        'loc-args',
27
        'launch-image',
28
    ];
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getFormat()
34
    {
35
        return 'apple';
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getContentType()
42
    {
43
        return 'application/json;charset=utf-8';
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getPayload()
50
    {
51
        $customPayloadData = null;
52
53
        if (!empty($this->options)) {
54
            if (!empty($this->options['custom-payload-data']) && is_array($this->options['custom-payload-data'])) {
55
                $customPayloadData = $this->options['custom-payload-data'];
56
            }
57
            $payload = array_intersect_key($this->options, array_fill_keys($this->supportedOptions, 0));
58
        } else {
59
            $payload = [];
60
        }
61
62
        if (is_array($this->alert)) {
63
            $alert = array_intersect_key($this->alert, array_fill_keys($this->supportedAlertProperties, 0));
64
            $payload += ['alert' => $alert];
65
        } elseif (is_scalar($this->alert)) {
66
            $payload += ['alert' => $this->alert];
67
        } else {
68
            throw new \RuntimeException('Invalid alert.');
69
        }
70
71
        $payload = ['aps' => $payload];
72
73
        if (!empty($customPayloadData)) {
74
            $payload += $customPayloadData;
75
        }
76
77
        return json_encode($payload);
78
    }
79
}
80