Completed
Push — master ( b8f451...161d28 )
by Dwight
9s
created

ApnMessage::credentials()   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 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace NotificationChannels\Apn;
4
5
class ApnMessage
6
{
7
    /**
8
     * The title of the notification.
9
     *
10
     * @var string
11
     */
12
    public $title;
13
14
    /**
15
     * The body of the notification.
16
     *
17
     * @var string
18
     */
19
    public $body;
20
21
    /**
22
     * The badge of the notification.
23
     *
24
     * @var int
25
     */
26
    public $badge;
27
28
    /**
29
     * The sound for the notification.
30
     *
31
     * @var string|null
32
     */
33
    public $sound;
34
35
    /**
36
     * The category for action button.
37
     *
38
     * @var string|null
39
     * */
40
    public $category;
41
42
    /**
43
     * Value indicating incoming resource in the notification.
44
     *
45
     * @var int|null
46
     */
47
    public $contentAvailable = null;
48
49
    /**
50
     * Additional data of the notification.
51
     *
52
     * @var array
53
     */
54
    public $custom = [];
55
56
    /**
57
     * Message specific credentials.
58
     *
59
     * @var ApnCredentials
60
     */
61
    public $credentials = null;
62
63
    /**
64
     * @param string|null $title
65
     * @param string|null $body
66
     * @param array $custom
67
     * @param null|int $badge
68
     *
69
     * @return static
70
     */
71 1
    public static function create($title = null, $body = null, $custom = [], $badge = null)
72
    {
73 1
        return new static($title, $body, $custom, $badge);
74
    }
75
76
    /**
77
     * @param string|null $title
78
     * @param string|null $body
79
     * @param array $custom
80
     * @param null|int $badge
81
     */
82 13
    public function __construct($title = null, $body = null, $custom = [], $badge = null)
83
    {
84 13
        $this->title = $title;
85 13
        $this->body = $body;
86 13
        $this->custom = $custom;
87 13
        $this->badge = $badge;
88 13
    }
89
90
    /**
91
     * Set the alert title of the notification.
92
     *
93
     * @param string $title
94
     *
95
     * @return $this
96
     */
97 1
    public function title($title)
98
    {
99 1
        $this->title = $title;
100
101 1
        return $this;
102
    }
103
104
    /**
105
     * Set the alert message of the notification.
106
     *
107
     * @param string $body
108
     *
109
     * @return $this
110
     */
111 1
    public function body($body)
112
    {
113 1
        $this->body = $body;
114
115 1
        return $this;
116
    }
117
118
    /**
119
     * Set the badge of the notification.
120
     *
121
     * @param int $badge
122
     *
123
     * @return $this
124
     */
125 1
    public function badge($badge)
126
    {
127 1
        $this->badge = $badge;
128
129 1
        return $this;
130
    }
131
132
    /**
133
     * Set the sound for the notification.
134
     *
135
     * @param string|null $sound
136
     *
137
     * @return $this
138
     */
139 2
    public function sound($sound = 'default')
140
    {
141 2
        $this->sound = $sound;
142
143 2
        return $this;
144
    }
145
146
    /**
147
     * Set category for this notification.
148
     *
149
     * @param string|null $category
150
     *
151
     * @return $this
152
     * */
153 1
    public function category($category)
154
    {
155 1
        $this->category = $category;
156
157 1
        return $this;
158
    }
159
160
    /**
161
     * Set content available value for this notification.
162
     *
163
     * @param int $value
164
     *
165
     * @return $this
166
     */
167 1
    public function contentAvailable($value = 1)
168
    {
169 1
        $this->contentAvailable = $value;
170
171 1
        return $this;
172
    }
173
174
    /**
175
     * Add custom data to the notification.
176
     *
177
     * @param string $key
178
     * @param mixed $value
179
     *
180
     * @return $this
181
     */
182 2
    public function custom($key, $value)
183
    {
184 2
        $this->custom[$key] = $value;
185
186 2
        return $this;
187
    }
188
189
    /**
190
     * Override the data of the notification.
191
     *
192
     * @param array $custom
193
     *
194
     * @return $this
195
     */
196 1
    public function setCustom($custom)
197
    {
198 1
        $this->custom = $custom;
199
200 1
        return $this;
201
    }
202
203
    /**
204
     * Add an action to the notification.
205
     *
206
     * @param string $action
207
     * @param mixed $params
208
     *
209
     * @return $this
210
     */
211 1
    public function action($action, $params = null)
212
    {
213 1
        return $this->custom('action', [
214 1
            'action' => $action,
215 1
            'params' => $params,
216
        ]);
217
    }
218
219
    /**
220
     * Set message specific credentials.
221
     *
222
     * @param \NotificationChannels\Apn\ApnCredentials $credentials
223
     * @return $this
224
     */
225
    public function credentials(ApnCredentials $credentials)
226
    {
227
        $this->credentials = $credentials;
228
229
        return $this;
230
    }
231
}
232