This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the MobileNotif package. |
||
5 | * |
||
6 | * For the full copyright and license information, please view the LICENSE |
||
7 | * file that was distributed with this source code. |
||
8 | */ |
||
9 | |||
10 | namespace LinkValue\MobileNotif\Model; |
||
11 | |||
12 | /** |
||
13 | * Apple Push Notification Service Message implementation. |
||
14 | * |
||
15 | * Refer to APNS documentation for more details. |
||
16 | * |
||
17 | * @see https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html |
||
18 | * |
||
19 | * @author Jamal Youssefi <[email protected]> |
||
20 | * @author Valentin Coulon <[email protected]> |
||
21 | */ |
||
22 | class ApnsMessage extends Message |
||
23 | { |
||
24 | // Default values |
||
25 | const DEFAULT_SOUND = 'default'; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $simpleAlert; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $alertTitle; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $alertBody; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $alertTitleLocKey; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | private $alertTitleLocArgs; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | private $alertActionLocKey; |
||
56 | |||
57 | /** |
||
58 | * @var string |
||
59 | */ |
||
60 | private $alertLocKey; |
||
61 | |||
62 | /** |
||
63 | * @var array |
||
64 | */ |
||
65 | private $alertLocArgs; |
||
66 | |||
67 | /** |
||
68 | * @var string |
||
69 | */ |
||
70 | private $alertLaunchImage; |
||
71 | |||
72 | /** |
||
73 | * @var int |
||
74 | */ |
||
75 | private $badge; |
||
76 | |||
77 | /** |
||
78 | * @var string |
||
79 | */ |
||
80 | private $sound; |
||
81 | |||
82 | /** |
||
83 | * @var int |
||
84 | */ |
||
85 | private $contentAvailable; |
||
86 | |||
87 | /** |
||
88 | * @var string |
||
89 | */ |
||
90 | private $category; |
||
91 | |||
92 | /** |
||
93 | * @var array |
||
94 | */ |
||
95 | private $data; |
||
96 | |||
97 | /** |
||
98 | * @var array |
||
99 | */ |
||
100 | private $action; |
||
101 | |||
102 | /** |
||
103 | * Constructor |
||
104 | */ |
||
105 | 44 | public function __construct() |
|
106 | { |
||
107 | 44 | parent::__construct(); |
|
108 | |||
109 | 44 | $this->sound = self::DEFAULT_SOUND; |
|
110 | 44 | $this->alertTitleLocArgs = array(); |
|
111 | 44 | $this->alertLocArgs = array(); |
|
112 | 44 | $this->data = array(); |
|
113 | 44 | } |
|
114 | |||
115 | /** |
||
116 | * Get full message payload. |
||
117 | * |
||
118 | * @return array |
||
119 | */ |
||
120 | 5 | public function getPayload() |
|
121 | { |
||
122 | // APNS base payload structure |
||
123 | $payload = array( |
||
124 | 5 | 'aps' => array(), |
|
125 | 5 | ); |
|
126 | |||
127 | // Build notification |
||
128 | 5 | if ($this->getPayloadAlertKeyValue()) { |
|
129 | 2 | $payload['aps']['alert'] = $this->getPayloadAlertKeyValue(); |
|
130 | 2 | } |
|
131 | |||
132 | // Build extra content |
||
133 | 5 | if (!is_null($this->getBadge())) { |
|
134 | 1 | $payload['aps']['badge'] = $this->getBadge(); |
|
135 | 1 | } |
|
136 | 5 | if ($this->getSound() !== self::DEFAULT_SOUND) { |
|
137 | 1 | $payload['aps']['sound'] = $this->getSound(); |
|
138 | 1 | } |
|
139 | 5 | if (!is_null($this->getContentAvailable())) { |
|
140 | 1 | $payload['aps']['content-available'] = $this->getContentAvailable(); |
|
141 | 1 | } |
|
142 | 5 | if ($this->getCategory()) { |
|
143 | 1 | $payload['aps']['category'] = $this->getCategory(); |
|
144 | 1 | } |
|
145 | 5 | if ($this->getData()) { |
|
146 | 1 | $payload['data'] = $this->getData(); |
|
147 | 1 | } |
|
148 | |||
149 | // Return payload |
||
150 | 5 | return $payload; |
|
151 | } |
||
152 | |||
153 | /** |
||
154 | * Get the value of Simple Alert. |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | 6 | public function getSimpleAlert() |
|
159 | { |
||
160 | 6 | return $this->simpleAlert; |
|
161 | } |
||
162 | |||
163 | /** |
||
164 | * Set the value of Simple Alert. |
||
165 | * |
||
166 | * @param string $simpleAlert |
||
167 | * |
||
168 | * @return self |
||
169 | */ |
||
170 | 3 | public function setSimpleAlert($simpleAlert) |
|
171 | { |
||
172 | 3 | if (!is_string($simpleAlert)) { |
|
173 | 1 | throw new \InvalidArgumentException('Simple Alert must be set with a value of type "string".'); |
|
174 | } |
||
175 | |||
176 | 2 | $this->simpleAlert = $simpleAlert; |
|
177 | |||
178 | 2 | return $this; |
|
179 | } |
||
180 | |||
181 | /** |
||
182 | * Get the value of Alert Title. |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | 5 | public function getAlertTitle() |
|
187 | { |
||
188 | 5 | return $this->alertTitle; |
|
189 | } |
||
190 | |||
191 | /** |
||
192 | * Set the value of Alert Title. |
||
193 | * |
||
194 | * @param string $alertTitle |
||
195 | * |
||
196 | * @return self |
||
197 | */ |
||
198 | 2 | public function setAlertTitle($alertTitle) |
|
199 | { |
||
200 | 2 | $this->alertTitle = $alertTitle; |
|
201 | |||
202 | 2 | return $this; |
|
203 | } |
||
204 | |||
205 | /** |
||
206 | * Get the value of Alert Body. |
||
207 | * |
||
208 | * @return string |
||
209 | */ |
||
210 | 5 | public function getAlertBody() |
|
211 | { |
||
212 | 5 | return $this->alertBody; |
|
213 | } |
||
214 | |||
215 | /** |
||
216 | * Set the value of Alert Body. |
||
217 | * |
||
218 | * @param string $alertBody |
||
219 | * |
||
220 | * @return self |
||
221 | */ |
||
222 | 2 | public function setAlertBody($alertBody) |
|
223 | { |
||
224 | 2 | $this->alertBody = $alertBody; |
|
225 | |||
226 | 2 | return $this; |
|
227 | } |
||
228 | |||
229 | /** |
||
230 | * Get the value of Alert Title Loc Key. |
||
231 | * |
||
232 | * @return string |
||
233 | */ |
||
234 | 5 | public function getAlertTitleLocKey() |
|
235 | { |
||
236 | 5 | return $this->alertTitleLocKey; |
|
237 | } |
||
238 | |||
239 | /** |
||
240 | * Set the value of Alert Title Loc Key. |
||
241 | * |
||
242 | * @param string $alertTitleLocKey |
||
243 | * |
||
244 | * @return self |
||
245 | */ |
||
246 | 2 | public function setAlertTitleLocKey($alertTitleLocKey) |
|
247 | { |
||
248 | 2 | $this->alertTitleLocKey = $alertTitleLocKey; |
|
249 | |||
250 | 2 | return $this; |
|
251 | } |
||
252 | |||
253 | /** |
||
254 | * Get the value of Alert Title Loc Args. |
||
255 | * |
||
256 | * @return array |
||
257 | */ |
||
258 | 5 | public function getAlertTitleLocArgs() |
|
259 | { |
||
260 | 5 | return $this->alertTitleLocArgs; |
|
261 | } |
||
262 | |||
263 | /** |
||
264 | * Set the value of Alert Title Loc Args. |
||
265 | * |
||
266 | * @param array $alertTitleLocArgs |
||
267 | * |
||
268 | * @return self |
||
269 | */ |
||
270 | 2 | public function setAlertTitleLocArgs(array $alertTitleLocArgs) |
|
271 | { |
||
272 | 2 | $this->alertTitleLocArgs = $alertTitleLocArgs; |
|
273 | |||
274 | 2 | return $this; |
|
275 | } |
||
276 | |||
277 | /** |
||
278 | * Get the value of Alert Action Loc Key. |
||
279 | * |
||
280 | * @return string |
||
281 | */ |
||
282 | 5 | public function getAlertActionLocKey() |
|
283 | { |
||
284 | 5 | return $this->alertActionLocKey; |
|
285 | } |
||
286 | |||
287 | /** |
||
288 | * Set the value of Alert Action Loc Key. |
||
289 | * |
||
290 | * @param string $alertActionLocKey |
||
291 | * |
||
292 | * @return self |
||
293 | */ |
||
294 | 2 | public function setAlertActionLocKey($alertActionLocKey) |
|
295 | { |
||
296 | 2 | $this->alertActionLocKey = $alertActionLocKey; |
|
297 | |||
298 | 2 | return $this; |
|
299 | } |
||
300 | |||
301 | /** |
||
302 | * Get the value of Alert Loc Key. |
||
303 | * |
||
304 | * @return string |
||
305 | */ |
||
306 | 5 | public function getAlertLocKey() |
|
307 | { |
||
308 | 5 | return $this->alertLocKey; |
|
309 | } |
||
310 | |||
311 | /** |
||
312 | * Set the value of Alert Loc Key. |
||
313 | * |
||
314 | * @param string $alertLocKey |
||
315 | * |
||
316 | * @return self |
||
317 | */ |
||
318 | 2 | public function setAlertLocKey($alertLocKey) |
|
319 | { |
||
320 | 2 | $this->alertLocKey = $alertLocKey; |
|
321 | |||
322 | 2 | return $this; |
|
323 | } |
||
324 | |||
325 | /** |
||
326 | * Get the value of Alert Loc Args. |
||
327 | * |
||
328 | * @return array |
||
329 | */ |
||
330 | 5 | public function getAlertLocArgs() |
|
331 | { |
||
332 | 5 | return $this->alertLocArgs; |
|
333 | } |
||
334 | |||
335 | /** |
||
336 | * Set the value of Alert Loc Args. |
||
337 | * |
||
338 | * @param array $alertLocArgs |
||
339 | * |
||
340 | * @return self |
||
341 | */ |
||
342 | 2 | public function setAlertLocArgs(array $alertLocArgs) |
|
343 | { |
||
344 | 2 | $this->alertLocArgs = $alertLocArgs; |
|
345 | |||
346 | 2 | return $this; |
|
347 | } |
||
348 | |||
349 | /** |
||
350 | * Get the value of Alert Launch Image. |
||
351 | * |
||
352 | * @return string |
||
353 | */ |
||
354 | 5 | public function getAlertLaunchImage() |
|
355 | { |
||
356 | 5 | return $this->alertLaunchImage; |
|
357 | } |
||
358 | |||
359 | /** |
||
360 | * Set the value of Alert Launch Image. |
||
361 | * |
||
362 | * @param string $alertLaunchImage |
||
363 | * |
||
364 | * @return self |
||
365 | */ |
||
366 | 2 | public function setAlertLaunchImage($alertLaunchImage) |
|
367 | { |
||
368 | 2 | $this->alertLaunchImage = $alertLaunchImage; |
|
369 | |||
370 | 2 | return $this; |
|
371 | } |
||
372 | |||
373 | /** |
||
374 | * Get the value of Badge. |
||
375 | * |
||
376 | * @return int |
||
377 | */ |
||
378 | 6 | public function getBadge() |
|
379 | { |
||
380 | 6 | return $this->badge; |
|
381 | } |
||
382 | |||
383 | /** |
||
384 | * Set the value of Badge. |
||
385 | * |
||
386 | * @param int $badge |
||
387 | * |
||
388 | * @return self |
||
389 | */ |
||
390 | 2 | public function setBadge($badge) |
|
391 | { |
||
392 | 2 | $this->badge = (int) $badge; |
|
393 | |||
394 | 2 | return $this; |
|
395 | } |
||
396 | |||
397 | /** |
||
398 | * Get the value of Sound. |
||
399 | * |
||
400 | * @return string |
||
401 | */ |
||
402 | 7 | public function getSound() |
|
403 | { |
||
404 | 7 | return $this->sound; |
|
405 | } |
||
406 | |||
407 | /** |
||
408 | * Set the value of Sound. |
||
409 | * |
||
410 | * @param string $sound |
||
411 | * |
||
412 | * @return self |
||
413 | */ |
||
414 | 2 | public function setSound($sound) |
|
415 | { |
||
416 | 2 | $this->sound = $sound; |
|
417 | |||
418 | 2 | return $this; |
|
419 | } |
||
420 | |||
421 | /** |
||
422 | * Get the value of Content Available. |
||
423 | * |
||
424 | * @return int |
||
425 | */ |
||
426 | 6 | public function getContentAvailable() |
|
427 | { |
||
428 | 6 | return $this->contentAvailable; |
|
429 | } |
||
430 | |||
431 | /** |
||
432 | * Set the value of Content Available. |
||
433 | * |
||
434 | * @param int $contentAvailable |
||
435 | * |
||
436 | * @return self |
||
437 | */ |
||
438 | 2 | public function setContentAvailable($contentAvailable) |
|
439 | { |
||
440 | 2 | $this->contentAvailable = (int) $contentAvailable; |
|
441 | |||
442 | 2 | return $this; |
|
443 | } |
||
444 | |||
445 | /** |
||
446 | * Get the value of Category. |
||
447 | * |
||
448 | * @return string |
||
449 | */ |
||
450 | 6 | public function getCategory() |
|
451 | { |
||
452 | 6 | return $this->category; |
|
453 | } |
||
454 | |||
455 | /** |
||
456 | * Set the value of Category. |
||
457 | * |
||
458 | * @param string $category |
||
459 | * |
||
460 | * @return self |
||
461 | */ |
||
462 | 2 | public function setCategory($category) |
|
463 | { |
||
464 | 2 | $this->category = $category; |
|
465 | |||
466 | 2 | return $this; |
|
467 | } |
||
468 | |||
469 | /** |
||
470 | * Get the data array. |
||
471 | * |
||
472 | * @return array |
||
473 | */ |
||
474 | 7 | public function getData() |
|
475 | { |
||
476 | 7 | return $this->data; |
|
477 | } |
||
478 | |||
479 | /** |
||
480 | * Set the data array. |
||
481 | * |
||
482 | * @param array $data |
||
483 | * |
||
484 | * @return self |
||
485 | */ |
||
486 | 3 | public function setData(array $data) |
|
487 | { |
||
488 | 3 | $this->data = $data; |
|
489 | |||
490 | 3 | return $this; |
|
491 | } |
||
492 | |||
493 | /** |
||
494 | * Set a key/value pair in the data array. |
||
495 | * |
||
496 | * @param string|int $key |
||
497 | * @param mixed $value |
||
498 | * |
||
499 | * @return self |
||
500 | */ |
||
501 | 2 | View Code Duplication | public function addData($key, $value) |
0 ignored issues
–
show
|
|||
502 | { |
||
503 | 2 | if (!is_string($key) && !is_int($key)) { |
|
504 | 1 | throw new \InvalidArgumentException('Data keys must be of type "string" or "integer".'); |
|
505 | } |
||
506 | |||
507 | 1 | $data = $this->getData(); |
|
508 | |||
509 | 1 | $data[$key] = $value; |
|
510 | |||
511 | 1 | return $this->setData($data); |
|
512 | } |
||
513 | |||
514 | /** |
||
515 | * Get the action array. |
||
516 | * |
||
517 | * @return array |
||
518 | */ |
||
519 | 6 | public function getAction() |
|
520 | { |
||
521 | 6 | return $this->action; |
|
522 | } |
||
523 | |||
524 | /** |
||
525 | * Set the action array. |
||
526 | * |
||
527 | * @param array $action |
||
528 | * |
||
529 | * @return self |
||
530 | */ |
||
531 | 3 | public function setAction(array $action) |
|
532 | { |
||
533 | 3 | $this->action = $action; |
|
534 | |||
535 | 3 | return $this; |
|
536 | } |
||
537 | |||
538 | /** |
||
539 | * Set an array in the action array. |
||
540 | * |
||
541 | * @param array $action |
||
542 | * |
||
543 | * @return self |
||
544 | */ |
||
545 | 1 | public function addAction(array $action) |
|
546 | { |
||
547 | 1 | $actions = $this->getAction(); |
|
548 | |||
549 | 1 | $actions[] = $action; |
|
550 | |||
551 | 1 | return $this->setAction($actions); |
|
552 | } |
||
553 | |||
554 | /** |
||
555 | * Get the value of the payload "alert" key. |
||
556 | * |
||
557 | * @return string|array |
||
558 | */ |
||
559 | 5 | private function getPayloadAlertKeyValue() |
|
560 | { |
||
561 | // Alert "string" (simple alert) |
||
562 | 5 | if ($this->getSimpleAlert()) { |
|
563 | 1 | return $this->getSimpleAlert(); |
|
564 | } |
||
565 | |||
566 | // Alert "array" (complex alert) |
||
567 | 4 | $payloadAlert = array(); |
|
568 | |||
569 | 4 | if ($this->getAlertTitle()) { |
|
570 | 1 | $payloadAlert['title'] = $this->getAlertTitle(); |
|
571 | 1 | } |
|
572 | 4 | if ($this->getAlertBody()) { |
|
573 | 1 | $payloadAlert['body'] = $this->getAlertBody(); |
|
574 | 1 | } |
|
575 | 4 | if ($this->getAlertTitleLocKey()) { |
|
576 | 1 | $payloadAlert['title-loc-key'] = $this->getAlertTitleLocKey(); |
|
577 | 1 | } |
|
578 | 4 | if ($this->getAlertTitleLocArgs()) { |
|
579 | 1 | $payloadAlert['title-loc-args'] = $this->getAlertTitleLocArgs(); |
|
580 | 1 | } |
|
581 | 4 | if ($this->getAlertActionLocKey()) { |
|
582 | 1 | $payloadAlert['action-loc-key'] = $this->getAlertActionLocKey(); |
|
583 | 1 | } |
|
584 | 4 | if ($this->getAlertLocKey()) { |
|
585 | 1 | $payloadAlert['loc-key'] = $this->getAlertLocKey(); |
|
586 | 1 | } |
|
587 | 4 | if ($this->getAlertLocArgs()) { |
|
588 | 1 | $payloadAlert['loc-args'] = $this->getAlertLocArgs(); |
|
589 | 1 | } |
|
590 | 4 | if ($this->getAlertLaunchImage()) { |
|
591 | 1 | $payloadAlert['launch-image'] = $this->getAlertLaunchImage(); |
|
592 | 1 | } |
|
593 | 4 | if ($this->getAction()) { |
|
594 | 1 | $payloadAlert['action'] = $this->getAction(); |
|
595 | 1 | } |
|
596 | |||
597 | 4 | return $payloadAlert; |
|
598 | } |
||
599 | } |
||
600 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.