Completed
Pull Request — master (#11)
by Oliver
02:28
created

ApnsMessage   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 439
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 31
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 439
ccs 91
cts 91
cp 1
rs 9.8

29 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getPayload() 0 23 1
A getAlertTitle() 0 4 1
A setAlertTitle() 0 6 1
A getAlertBody() 0 4 1
A setAlertBody() 0 6 1
A getAlertTitleLocKey() 0 4 1
A setAlertTitleLocKey() 0 6 1
A getAlertTitleLocArgs() 0 4 1
A setAlertTitleLocArgs() 0 6 1
A getAlertActionLocKey() 0 4 1
A setAlertActionLocKey() 0 6 1
A getAlertLocKey() 0 4 1
A setAlertLocKey() 0 6 1
A getAlertLocArgs() 0 4 1
A setAlertLocArgs() 0 6 1
A getAlertLaunchImage() 0 4 1
A setAlertLaunchImage() 0 6 1
A getBadge() 0 4 1
A setBadge() 0 6 1
A getSound() 0 4 2
A setSound() 0 6 1
A getContentAvailable() 0 4 1
A setContentAvailable() 0 6 1
A getCategory() 0 4 1
A setCategory() 0 6 1
A getData() 0 4 1
A setData() 0 10 2
A addData() 0 8 1
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: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9.
16
 *
17
 * @author  Jamal Youssefi <[email protected]>
18
 * @author  Valentin Coulon <[email protected]>
19
 */
20
class ApnsMessage extends Message
21
{
22
    /**
23
     * @var string
24
     */
25
    private $alertTitle;
26
27
    /**
28
     * @var string
29
     */
30
    private $alertBody;
31
32
    /**
33
     * @var string
34
     */
35
    private $alertTitleLocKey;
36
37
    /**
38
     * @var array
39
     */
40
    private $alertTitleLocArgs;
41
42
    /**
43
     * @var string
44
     */
45
    private $alertActionLocKey;
46
47
    /**
48
     * @var string
49
     */
50
    private $alertLocKey;
51
52
    /**
53
     * @var array
54
     */
55
    private $alertLocArgs;
56
57
    /**
58
     * @var string
59
     */
60
    private $alertLaunchImage;
61
62
    /**
63
     * @var string
64
     */
65
    private $badge;
66
67
    /**
68
     * @var string
69
     */
70
    private $sound;
71
72
    /**
73
     * @var int
74
     */
75
    private $contentAvailable;
76
77
    /**
78
     * @var string
79
     */
80
    private $category;
81
82
    /**
83
     * @var array
84
     */
85
    private $data;
86
87
    /**
88
     * Constructor
89
     */
90 35
    public function __construct()
91
    {
92 35
        parent::__construct();
93
94 35
        $this->alertTitleLocArgs = array();
95 35
        $this->alertLocArgs = array();
96 35
        $this->data = array();
97 35
    }
98
99
    /**
100
     * @return array
101
     */
102 2
    public function getPayload()
103
    {
104
        $payload = array(
105
            'aps' => array(
106
                'alert' => array(
107 2
                    'title' => $this->getAlertTitle(),
108 2
                    'body' => $this->getAlertBody(),
109 2
                    'title-loc-key' => $this->getAlertTitleLocKey(),
110 2
                    'title-loc-args' => $this->getAlertTitleLocArgs(),
111 2
                    'action-loc-key' => $this->getAlertActionLocKey(),
112 2
                    'loc-key' => $this->getAlertLocKey(),
113 2
                    'loc-args' => $this->getAlertLocArgs(),
114 2
                    'launch-image' => $this->getAlertLaunchImage(),
115
                ),
116 2
                'badge' => $this->getBadge(),
117 2
                'sound' => $this->getSound(),
118 2
                'content-available' => $this->getContentAvailable(),
119 2
                'category' => $this->getCategory(),
120
            ),
121
        );
122
123 2
        return array_merge($payload, $this->getData());
124
    }
125
126
    /**
127
     * Get the value of Alert Title.
128
     *
129
     * @return string
130
     */
131 3
    public function getAlertTitle()
132
    {
133 3
        return $this->alertTitle;
134
    }
135
136
    /**
137
     * Set the value of Alert Title.
138
     *
139
     * @param string $alertTitle
140
     *
141
     * @return self
142
     */
143 1
    public function setAlertTitle($alertTitle)
144
    {
145 1
        $this->alertTitle = $alertTitle;
146
147 1
        return $this;
148
    }
149
150
    /**
151
     * Get the value of Alert Body.
152
     *
153
     * @return string
154
     */
155 3
    public function getAlertBody()
156
    {
157 3
        return $this->alertBody;
158
    }
159
160
    /**
161
     * Set the value of Alert Body.
162
     *
163
     * @param string $alertBody
164
     *
165
     * @return self
166
     */
167 1
    public function setAlertBody($alertBody)
168
    {
169 1
        $this->alertBody = $alertBody;
170
171 1
        return $this;
172
    }
173
174
    /**
175
     * Get the value of Alert Title Loc Key.
176
     *
177
     * @return string
178
     */
179 3
    public function getAlertTitleLocKey()
180
    {
181 3
        return $this->alertTitleLocKey;
182
    }
183
184
    /**
185
     * Set the value of Alert Title Loc Key.
186
     *
187
     * @param string $alertTitleLocKey
188
     *
189
     * @return self
190
     */
191 1
    public function setAlertTitleLocKey($alertTitleLocKey)
192
    {
193 1
        $this->alertTitleLocKey = $alertTitleLocKey;
194
195 1
        return $this;
196
    }
197
198
    /**
199
     * Get the value of Alert Title Loc Args.
200
     *
201
     * @return array
202
     */
203 3
    public function getAlertTitleLocArgs()
204
    {
205 3
        return $this->alertTitleLocArgs;
206
    }
207
208
    /**
209
     * Set the value of Alert Title Loc Args.
210
     *
211
     * @param array $alertTitleLocArgs
212
     *
213
     * @return self
214
     */
215 1
    public function setAlertTitleLocArgs(array $alertTitleLocArgs)
216
    {
217 1
        $this->alertTitleLocArgs = $alertTitleLocArgs;
218
219 1
        return $this;
220
    }
221
222
    /**
223
     * Get the value of Alert Action Loc Key.
224
     *
225
     * @return string
226
     */
227 3
    public function getAlertActionLocKey()
228
    {
229 3
        return $this->alertActionLocKey;
230
    }
231
232
    /**
233
     * Set the value of Alert Action Loc Key.
234
     *
235
     * @param string $alertActionLocKey
236
     *
237
     * @return self
238
     */
239 1
    public function setAlertActionLocKey($alertActionLocKey)
240
    {
241 1
        $this->alertActionLocKey = $alertActionLocKey;
242
243 1
        return $this;
244
    }
245
246
    /**
247
     * Get the value of Alert Loc Key.
248
     *
249
     * @return string
250
     */
251 3
    public function getAlertLocKey()
252
    {
253 3
        return $this->alertLocKey;
254
    }
255
256
    /**
257
     * Set the value of Alert Loc Key.
258
     *
259
     * @param string $alertLocKey
260
     *
261
     * @return self
262
     */
263 1
    public function setAlertLocKey($alertLocKey)
264
    {
265 1
        $this->alertLocKey = $alertLocKey;
266
267 1
        return $this;
268
    }
269
270
    /**
271
     * Get the value of Alert Loc Args.
272
     *
273
     * @return array
274
     */
275 3
    public function getAlertLocArgs()
276
    {
277 3
        return $this->alertLocArgs;
278
    }
279
280
    /**
281
     * Set the value of Alert Loc Args.
282
     *
283
     * @param array $alertLocArgs
284
     *
285
     * @return self
286
     */
287 1
    public function setAlertLocArgs(array $alertLocArgs)
288
    {
289 1
        $this->alertLocArgs = $alertLocArgs;
290
291 1
        return $this;
292
    }
293
294
    /**
295
     * Get the value of Alert Launch Image.
296
     *
297
     * @return string
298
     */
299 3
    public function getAlertLaunchImage()
300
    {
301 3
        return $this->alertLaunchImage;
302
    }
303
304
    /**
305
     * Set the value of Alert Launch Image.
306
     *
307
     * @param string $alertLaunchImage
308
     *
309
     * @return self
310
     */
311 1
    public function setAlertLaunchImage($alertLaunchImage)
312
    {
313 1
        $this->alertLaunchImage = $alertLaunchImage;
314
315 1
        return $this;
316
    }
317
318
    /**
319
     * Get the value of Badge.
320
     *
321
     * @return string
322
     */
323 3
    public function getBadge()
324
    {
325 3
        return $this->badge;
326
    }
327
328
    /**
329
     * Set the value of Badge.
330
     *
331
     * @param string $badge
332
     *
333
     * @return self
334
     */
335 1
    public function setBadge($badge)
336
    {
337 1
        $this->badge = $badge;
338
339 1
        return $this;
340
    }
341
342
    /**
343
     * Get the value of Sound.
344
     *
345
     * @return string
346
     */
347 4
    public function getSound()
348
    {
349 4
        return $this->sound ? $this->sound : 'default';
350
    }
351
352
    /**
353
     * Set the value of Sound.
354
     *
355
     * @param string $sound
356
     *
357
     * @return self
358
     */
359 1
    public function setSound($sound)
360
    {
361 1
        $this->sound = $sound;
362
363 1
        return $this;
364
    }
365
366
    /**
367
     * Get the value of Content Available.
368
     *
369
     * @return int
370
     */
371 3
    public function getContentAvailable()
372
    {
373 3
        return $this->contentAvailable;
374
    }
375
376
    /**
377
     * Set the value of Content Available.
378
     *
379
     * @param int $contentAvailable
380
     *
381
     * @return self
382
     */
383 1
    public function setContentAvailable($contentAvailable)
384
    {
385 1
        $this->contentAvailable = $contentAvailable;
386
387 1
        return $this;
388
    }
389
390
    /**
391
     * Get the value of Category.
392
     *
393
     * @return string
394
     */
395 3
    public function getCategory()
396
    {
397 3
        return $this->category;
398
    }
399
400
    /**
401
     * Set the value of Category.
402
     *
403
     * @param string $category
404
     *
405
     * @return self
406
     */
407 1
    public function setCategory($category)
408
    {
409 1
        $this->category = $category;
410
411 1
        return $this;
412
    }
413
414
    /**
415
     * Get the data array.
416
     *
417
     * @return array
418
     */
419 5
    public function getData()
420
    {
421 5
        return $this->data;
422
    }
423
424
    /**
425
     * Set the data array.
426
     *
427
     * @param array $data
428
     *
429
     * @return self
430
     */
431 4
    public function setData(array $data)
432
    {
433 4
        if (isset($data['aps'])) {
434 2
            throw new \RuntimeException('The key "aps" is reserved. Do not use it for data.');
435
        }
436
437 2
        $this->data = $data;
438
439 2
        return $this;
440
    }
441
442
    /**
443
     * Add a value at a specific key to the data array.
444
     *
445
     * @param string $key
446
     * @param string $value
447
     *
448
     * @return self
449
     */
450 2
    public function addData($key, $value)
451
    {
452 2
        $data = $this->getData();
453
454 2
        $data[$key] = $value;
455
456 2
        return $this->setData($data);
457
    }
458
}
459