Completed
Push — master ( 8b1a0a...6138d3 )
by Barry vd.
06:11
created

GcmMessage::data()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
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
    public static function create($title = null, $message = null, $data = [], $priority = self::PRIORITY_NORMAL, $sound = self::DEFAULT_SOUND)
64
    {
65
        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
    public function __construct($title = null, $message = null, $data = [], $priority = self::PRIORITY_NORMAL, $sound = self::DEFAULT_SOUND)
76
    {
77
        $this->title = $title;
78
        $this->message = $message;
79
        $this->data = $data;
80
        $this->priority = $priority;
81
        $this->sound = $sound;
82
    }
83
84
    /**
85
     * Set the title of the notification.
86
     *
87
     * @param string $title
88
     *
89
     * @return $this
90
     */
91
    public function title($title)
92
    {
93
        $this->title = $title;
94
95
        return $this;
96
    }
97
98
    /**
99
     * Set the message of the notification.
100
     *
101
     * @param string $message
102
     *
103
     * @return $this
104
     */
105
    public function message($message)
106
    {
107
        $this->message = $message;
108
109
        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
    public function priority($priority)
134
    {
135
        $this->priority = $priority;
136
137
        return $this;
138
    }
139
140
    /**
141
     * Set the sound for notification
142
     *
143
     * @param string $sound
144
     *
145
     * @return $this
146
     */
147
    public function sound($sound)
148
    {
149
        $this->sound = $sound;
150
151
        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
    public function data($key, $value)
163
    {
164
        $this->data[$key] = $value;
165
166
        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