Completed
Push — master ( 58c117...c459c0 )
by Barry vd.
07:19
created

GcmMessage::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 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
    const DEFAULT_SOUND = 'default';
11
12
    /**
13
     * The title of the notification.
14
     *
15
     * @var string
16
     */
17
    public $title;
18
19
    /**
20
     * The message of the notification.
21
     *
22
     * @var string
23
     */
24
    public $message;
25
26
    /**
27
     * The badge of the notification.
28
     * @warning UNUSED
29
     *
30
     * @var int
31
     */
32
    public $badge;
33
34
    /**
35
     * The priority of the notification.
36
     *
37
     * @var string
38
     */
39
    public $priority = self::PRIORITY_NORMAL;
40
41
    /**
42
     * Notification sound
43
     *
44
     * @var string
45
     */
46
    public $sound = self::DEFAULT_SOUND;
47
48
    /**
49
     * Additional data of the notification.
50
     *
51
     * @var array
52
     */
53
    public $data = [];
54
55
    /**
56
     * @param string|null $title
57
     * @param string|null $message
58
     * @param array $data
59
     * @param string $priority
60
     *
61
     * @return static
62
     */
63 1
    public static function create($title = null, $message = null, $data = [], $priority = self::PRIORITY_NORMAL, $sound = self::DEFAULT_SOUND)
64
    {
65 1
        return new static($title, $message, $data, $priority, $sound);
66
    }
67
68
    /**
69
     * @param string|null $title
70
     * @param string|null $message
71
     * @param array $data
72
     * @param string $priority
73
     * @param string $sound
74
     */
75 10
    public function __construct($title = null, $message = null, $data = [], $priority = self::PRIORITY_NORMAL, $sound = self::DEFAULT_SOUND)
76
    {
77 10
        $this->title = $title;
78 10
        $this->message = $message;
79 10
        $this->data = $data;
80 10
        $this->priority = $priority;
81 10
        $this->sound = $sound;
82 10
    }
83
84
    /**
85
     * Set the title of the notification.
86
     *
87
     * @param string $title
88
     *
89
     * @return $this
90
     */
91 1
    public function title($title)
92
    {
93 1
        $this->title = $title;
94
95 1
        return $this;
96
    }
97
98
    /**
99
     * Set the message of the notification.
100
     *
101
     * @param string $message
102
     *
103
     * @return $this
104
     */
105 1
    public function message($message)
106
    {
107 1
        $this->message = $message;
108
109 1
        return $this;
110
    }
111
112
    /**
113
     * Set the badge of the notification.
114
     *
115
     * @param int $badge
116
     *
117
     * @return $this
118
     */
119
    public function badge($badge)
120
    {
121
        $this->badge = $badge;
122
123
        return $this;
124
    }
125
126
    /**
127
     * Set the priority of the notification.
128
     *
129
     * @param string $priority
130
     *
131
     * @return $this
132
     */
133 1
    public function priority($priority)
134
    {
135 1
        $this->priority = $priority;
136
137 1
        return $this;
138
    }
139
140
    /**
141
     * Set the sound for notification
142
     *
143
     * @param string $sound
144
     *
145
     * @return $this
146
     */
147 1
    public function sound($sound)
148
    {
149 1
        $this->sound = $sound;
150
151 1
        return $this;
152
    }
153
154
    /**
155
     * Add data to the notification.
156
     *
157
     * @param string $key
158
     * @param mixed $value
159
     *
160
     * @return $this
161
     */
162 1
    public function data($key, $value)
163
    {
164 1
        $this->data[$key] = $value;
165
166 1
        return $this;
167
    }
168
169
    /**
170
     * Override the data of the notification.
171
     *
172
     * @param array $data
173
     * @return $this
174
     */
175
    public function setData($data)
176
    {
177
        $this->data = $data;
178
179
        return $this;
180
    }
181
182
    /**
183
     * Add an action to the notification.
184
     *
185
     * @param string $action
186
     * @param mixed $params
187
     *
188
     * @return $this
189
     */
190
    public function action($action, $params = null)
191
    {
192
        return $this->data('action', [
193
            'action' => $action,
194
            'params' => $params,
195
        ]);
196
    }
197
}
198