Conditions | 7 |
Paths | 15 |
Total Lines | 30 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
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 |