Completed
Push — master ( 924db6...cc24e6 )
by Dwight
10:25 queued 05:55
created

Packet   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 63
ccs 0
cts 34
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setNotification() 0 6 1
F toJson() 0 35 9
1
<?php
2
3
namespace NotificationChannels\Gcm;
4
5
use Zend\Json\Json;
6
use ZendService\Google\Gcm\Message;
7
8
class Packet extends Message
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $notification;
14
15
    /**
16
     * Set the notification.
17
     *
18
     * @param array $notification
19
     * @return Message
20
     */
21
    public function setNotification(array $notification)
22
    {
23
        $this->notification = $notification;
24
25
        return $this;
26
    }
27
28
    /**
29
     * To JSON
30
     * Utility method to put the JSON into the
31
     * GCM proper format for sending the message.
32
     *
33
     * @return string
34
     */
35
    public function toJson()
36
    {
37
        $json = [];
38
39
        if ( ! empty($this->registrationIds)) {
40
            $json['registration_ids'] = $this->registrationIds;
41
        }
42
43
        if ($this->collapseKey) {
44
            $json['collapse_key'] = $this->collapseKey;
45
        }
46
47
        if ( ! empty($this->data)) {
48
            $json['data'] = $this->data;
49
        }
50
51
        if ( ! empty($this->notification)) {
52
            $json['notification'] = $this->notification;
53
        }
54
55
        if ($this->delayWhileIdle) {
56
            $json['delay_while_idle'] = $this->delayWhileIdle;
57
        }
58
        if ($this->timeToLive != 2419200) {
59
            $json['time_to_live'] = $this->timeToLive;
60
        }
61
        if ($this->restrictedPackageName) {
62
            $json['restricted_package_name'] = $this->restrictedPackageName;
63
        }
64
        if ($this->dryRun) {
65
            $json['dry_run'] = $this->dryRun;
66
        }
67
68
        return Json::encode($json);
69
    }
70
}
71