Completed
Push — master ( 0d4684...fff311 )
by Chris
01:24
created

FcmMessage::getTimeToLive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace NotificationChannels\Fcm;
4
5
use Kreait\Firebase\Messaging\Message;
6
use NotificationChannels\Fcm\Resources\AndroidConfig;
7
use NotificationChannels\Fcm\Resources\ApnsConfig;
8
use NotificationChannels\Fcm\Resources\FcmOptions;
9
use NotificationChannels\Fcm\Resources\Notification;
10
use NotificationChannels\Fcm\Resources\WebpushConfig;
11
12
class FcmMessage implements Message
13
{
14
    /**
15
     * @var string|null
16
     */
17
    protected $name;
18
19
    /**
20
     * @var array|null
21
     */
22
    protected $data;
23
24
    /**
25
     * @var Notification|null
26
     */
27
    protected $notification;
28
29
    /**
30
     * @var AndroidConfig|null
31
     */
32
    protected $android;
33
34
    /**
35
     * @var WebpushConfig|null
36
     */
37
    protected $webpush;
38
39
    /**
40
     * @var ApnsConfig|null
41
     */
42
    protected $apns;
43
44
    /**
45
     * @var FcmOptions|null
46
     */
47
    protected $fcmOptions;
48
49
    /**
50
     * @var string|null
51
     */
52
    protected $token;
53
54
    /**
55
     * @var string|null
56
     */
57
    protected $topic;
58
59
    /**
60
     * @var string|null
61
     */
62
    protected $condition;
63
64
    public static function create(): self
65
    {
66
        return new self;
67
    }
68
69
    /**
70
     * @return string|null
71
     */
72
    public function getName(): ?string
73
    {
74
        return $this->name;
75
    }
76
77
    /**
78
     * @param string|null $name
79
     * @return FcmMessage
80
     */
81
    public function setName(?string $name): self
82
    {
83
        $this->name = $name;
84
85
        return $this;
86
    }
87
88
    /**
89
     * @return array|null
90
     */
91
    public function getData(): ?array
92
    {
93
        return $this->data;
94
    }
95
96
    /**
97
     * @param array|null $data
98
     * @return FcmMessage
99
     */
100
    public function setData(?array $data): self
101
    {
102
        $this->data = $data;
103
104
        return $this;
105
    }
106
107
    /**
108
     * @return Notification|null
109
     */
110
    public function getNotification(): ?Notification
111
    {
112
        return $this->notification;
113
    }
114
115
    /**
116
     * @param Notification|null $notification
117
     * @return FcmMessage
118
     */
119
    public function setNotification(?Notification $notification): self
120
    {
121
        $this->notification = $notification;
122
123
        return $this;
124
    }
125
126
    /**
127
     * @return AndroidConfig|null
128
     */
129
    public function getAndroid(): ?AndroidConfig
130
    {
131
        return $this->android;
132
    }
133
134
    /**
135
     * @param AndroidConfig|null $android
136
     * @return FcmMessage
137
     */
138
    public function setAndroid(?AndroidConfig $android): self
139
    {
140
        $this->android = $android;
141
142
        return $this;
143
    }
144
145
    /**
146
     * @return WebpushConfig|null
147
     */
148
    public function getWebpush(): ?WebpushConfig
149
    {
150
        return $this->webpush;
151
    }
152
153
    /**
154
     * @param WebpushConfig|null $webpush
155
     * @return FcmMessage
156
     */
157
    public function setWebpush(?WebpushConfig $webpush): self
158
    {
159
        $this->webpush = $webpush;
160
161
        return $this;
162
    }
163
164
    /**
165
     * @return ApnsConfig|null
166
     */
167
    public function getApns(): ?ApnsConfig
168
    {
169
        return $this->apns;
170
    }
171
172
    /**
173
     * @param ApnsConfig|null $apns
174
     * @return FcmMessage
175
     */
176
    public function setApns(?ApnsConfig $apns): self
177
    {
178
        $this->apns = $apns;
179
180
        return $this;
181
    }
182
183
    /**
184
     * @return FcmOptions|null
185
     */
186
    public function getFcmOptions(): ?FcmOptions
187
    {
188
        return $this->fcmOptions;
189
    }
190
191
    /**
192
     * @param FcmOptions|null $fcmOptions
193
     * @return FcmMessage
194
     */
195
    public function setFcmOptions(?FcmOptions $fcmOptions): self
196
    {
197
        $this->fcmOptions = $fcmOptions;
198
199
        return $this;
200
    }
201
202
    /**
203
     * @return string|null
204
     */
205
    public function getToken(): ?string
206
    {
207
        return $this->token;
208
    }
209
210
    /**
211
     * @param string|null $token
212
     * @return FcmMessage
213
     */
214
    public function setToken(?string $token): self
215
    {
216
        $this->token = $token;
217
218
        return $this;
219
    }
220
221
    /**
222
     * @return string|null
223
     */
224
    public function getTopic(): ?string
225
    {
226
        return $this->topic;
227
    }
228
229
    /**
230
     * @param string|null $topic
231
     * @return FcmMessage
232
     */
233
    public function setTopic(?string $topic): self
234
    {
235
        $this->topic = $topic;
236
237
        return $this;
238
    }
239
240
    /**
241
     * @return string|null
242
     */
243
    public function getCondition(): ?string
244
    {
245
        return $this->condition;
246
    }
247
248
    /**
249
     * @param string|null $condition
250
     * @return FcmMessage
251
     */
252
    public function setCondition(?string $condition): self
253
    {
254
        $this->condition = $condition;
255
256
        return $this;
257
    }
258
259
    public function toArray()
260
    {
261
        return [
262
            'name' => $this->getName(),
263
            'data' => $this->getData(),
264
            'notification' => ! is_null($this->getNotification()) ? $this->getNotification()->toArray() : null,
265
            'android' => ! is_null($this->getAndroid()) ? $this->getAndroid()->toArray() : null,
266
            'webpush' => ! is_null($this->getWebpush()) ? $this->getWebpush()->toArray() : null,
267
            'apns' => ! is_null($this->getApns()) ? $this->getApns()->toArray() : null,
268
            'fcm_options' => ! is_null($this->getFcmOptions()) ? $this->getFcmOptions()->toArray() : null,
269
            'token' => $this->getToken(),
270
            'topic' => $this->getTopic(),
271
            'condition' => $this->getCondition(),
272
        ];
273
    }
274
275
    public function jsonSerialize()
276
    {
277
        return $this->toArray();
278
    }
279
}
280