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

GcmMessage::priority()   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
    /**
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