Completed
Branch master (69595d)
by Freek
10:42 queued 08:57
created

GcmMessage   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 168
Duplicated Lines 0 %

Coupling/Cohesion

Components 5
Dependencies 0

Test Coverage

Coverage 66.67%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 9
c 3
b 1
f 1
lcom 5
cbo 0
dl 0
loc 168
ccs 20
cts 30
cp 0.6667
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A __construct() 0 7 1
A title() 0 6 1
A message() 0 6 1
A badge() 0 6 1
A priority() 0 6 1
A data() 0 6 1
A setData() 0 6 1
A action() 0 7 1
1
<?php
2
3
namespace NotificationChannels\Gcm;
4
5
class GcmMessage
6
{
7
    const PRIORITY_NORMAL = 'normal';
8
    const PRIORITY_HIGH = 'high';
9
10
    /**
11
     * The title of the notification.
12
     *
13
     * @var string
14
     */
15
    public $title;
16
17
    /**
18
     * The message of the notification.
19
     *
20
     * @var string
21
     */
22
    public $message;
23
24
    /**
25
     * The badge of the notification.
26
     * @warning UNUSED
27
     *
28
     * @var int
29
     */
30
    public $badge;
31
32
    /**
33
     * The priority of the notification.
34
     *
35
     * @var string
36
     */
37
    public $priority = self::PRIORITY_NORMAL;
38
39
    /**
40
     * Additional data of the notification.
41
     *
42
     * @var array
43
     */
44
    public $data = [];
45
46
    /**
47
     * @param string|null $title
48
     * @param string|null $message
49
     * @param array $data
50
     * @param string $priority
51
     *
52
     * @return static
53
     */
54 1
    public static function create($title = null, $message = null, $data = [], $priority = self::PRIORITY_NORMAL)
55
    {
56 1
        return new static($title, $message, $data, $priority);
57
    }
58
59
    /**
60
     * @param string|null $title
61
     * @param string|null $message
62
     * @param array $data
63
     * @param string $priority
64
     */
65 8
    public function __construct($title = null, $message = null, $data = [], $priority = self::PRIORITY_NORMAL)
66
    {
67 8
        $this->title = $title;
68 8
        $this->message = $message;
69 8
        $this->data = $data;
70 8
        $this->priority = $priority;
71 8
    }
72
73
    /**
74
     * Set the title of the notification.
75
     *
76
     * @param string $title
77
     *
78
     * @return $this
79
     */
80 1
    public function title($title)
81
    {
82 1
        $this->title = $title;
83
84 1
        return $this;
85
    }
86
87
    /**
88
     * Set the message of the notification.
89
     *
90
     * @param string $message
91
     *
92
     * @return $this
93
     */
94 1
    public function message($message)
95
    {
96 1
        $this->message = $message;
97
98 1
        return $this;
99
    }
100
101
    /**
102
     * Set the badge of the notification.
103
     *
104
     * @param int $badge
105
     *
106
     * @return $this
107
     */
108
    public function badge($badge)
109
    {
110
        $this->badge = $badge;
111
112
        return $this;
113
    }
114
115
    /**
116
     * Set the priority of the notification.
117
     *
118
     * @param string $priority
119
     *
120
     * @return $this
121
     */
122 1
    public function priority($priority)
123
    {
124 1
        $this->priority = $priority;
125
126 1
        return $this;
127
    }
128
129
    /**
130
     * Add data to the notification.
131
     *
132
     * @param string $key
133
     * @param mixed $value
134
     *
135
     * @return $this
136
     */
137 1
    public function data($key, $value)
138
    {
139 1
        $this->data[$key] = $value;
140
141 1
        return $this;
142
    }
143
144
    /**
145
     * Override the data of the notification.
146
     *
147
     * @param array $data
148
     * @return $this
149
     */
150
    public function setData($data)
151
    {
152
        $this->data = $data;
153
154
        return $this;
155
    }
156
157
    /**
158
     * Add an action to the notification.
159
     *
160
     * @param string $action
161
     * @param mixed $params
162
     *
163
     * @return $this
164
     */
165
    public function action($action, $params = null)
166
    {
167
        return $this->data('action', [
168
            'action' => $action,
169
            'params' => $params,
170
        ]);
171
    }
172
}
173