Completed
Pull Request — master (#8)
by Romain
04:20
created

OptionsBuilder::getRestrictedPackageName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace ker0x\Push\Adapter\Fcm\Message;
3
4
use ker0x\Push\Adapter\Fcm\Message\Exception\InvalidOptionsException;
5
6
/**
7
 * Class OptionsBuilder
8
 * @package ker0x\Push\Adapter\Fcm\Message
9
 */
10
class OptionsBuilder
11
{
12
13
    /**
14
     * Normal priority for the notification.
15
     */
16
    const NORMAL = 'normal';
17
18
    /**
19
     * High priority for the notification.
20
     */
21
    const HIGH = 'high';
22
23
    /**
24
     * This parameter identifies a group of messages.
25
     *
26
     * @var null|string
27
     */
28
    protected $collapseKey;
29
30
    /**
31
     * Sets the priority of the message.
32
     *
33
     * @var null|string
34
     */
35
    protected $priority;
36
37
    /**
38
     * When a notification or message is sent and this is set to true,
39
     * an inactive client app is awoken.
40
     *
41
     * @var bool
42
     */
43
    protected $contentAvailable = false;
44
45
    /**
46
     * This parameter specifies how long (in seconds) the message should be kept
47
     * in FCM storage if the device is offline.
48
     *
49
     * @var null|int
50
     */
51
    protected $timeToLive;
52
53
    /**
54
     * This parameter specifies the package name of the application where the registration
55
     * tokens must match in order to receive the message.
56
     *
57
     * @var null|string
58
     */
59
    protected $restrictedPackageName;
60
61
    /**
62
     * This parameter, when set to true, allows developers to test a request without
63
     * actually sending a message.
64
     *
65
     * @var bool
66
     */
67
    protected $dryRun = false;
68
69
    /**
70
     * Getter for collapseKey.
71
     *
72
     * @return string
73
     */
74
    public function getCollapseKey()
75
    {
76
        return $this->collapseKey;
77
    }
78
79
    /**
80
     * Setter for collapseKey.
81
     *
82
     * @param string $collapseKey Identifier for a group of messages.
83
     * @return $this
84
     * @throws \ker0x\Push\Adapter\Fcm\Message\Exception\InvalidOptionsException
85
     */
86
    public function setCollapseKey($collapseKey)
87
    {
88
        if (!is_string($collapseKey)) {
89
            throw InvalidOptionsException::mustBeString('collapse_key');
90
        }
91
        $this->collapseKey = $collapseKey;
92
93
        return $this;
94
    }
95
96
    /**
97
     * Getter for priority.
98
     *
99
     * @return string
100
     */
101
    public function getPriority()
102
    {
103
        return $this->priority;
104
    }
105
106
    /**
107
     * Setter for priority.
108
     *
109
     * @param string $priority Priority of the message.
110
     * @return $this
111
     * @throws \ker0x\Push\Adapter\Fcm\Message\Exception\InvalidOptionsException
112
     */
113
    public function setPriority($priority)
114
    {
115
        if (!in_array($priority, [self::NORMAL, self::HIGH])) {
116
            throw InvalidOptionsException::invalidPriority();
117
        }
118
        $this->priority = $priority;
119
120
        return $this;
121
    }
122
123
    /**
124
     * Getter for contentAvailable.
125
     *
126
     * @return bool
127
     */
128
    public function isContentAvailable()
129
    {
130
        return $this->contentAvailable;
131
    }
132
133
    /**
134
     * Setter for contentAvailable.
135
     *
136
     * @param bool $contentAvailable Awake an inactive client app if set to `true`.
137
     * @return $this
138
     * @throws \ker0x\Push\Adapter\Fcm\Message\Exception\InvalidOptionsException
139
     */
140
    public function setContentAvailable($contentAvailable)
141
    {
142
        if (!is_bool($contentAvailable)) {
143
            throw InvalidOptionsException::mustBeBool('content_available');
144
        }
145
        $this->contentAvailable = $contentAvailable;
146
147
        return $this;
148
    }
149
150
    /**
151
     * Getter for timeToLive.
152
     *
153
     * @return string
154
     */
155
    public function getTimeToLive()
156
    {
157
        return $this->timeToLive;
158
    }
159
160
    /**
161
     * Setter for timeToLive.
162
     *
163
     * @param int $timeToLive How long (in seconds) the message should be kept in FCM storage.
164
     * @return $this
165
     * @throws \ker0x\Push\Adapter\Fcm\Message\Exception\InvalidOptionsException
166
     */
167
    public function setTimeToLive($timeToLive)
168
    {
169
        if (!is_int($timeToLive) || $timeToLive < 0 || $timeToLive > 2419200) {
170
            throw InvalidOptionsException::invalidTimeToLive($timeToLive);
171
        }
172
        $this->timeToLive = $timeToLive;
173
174
        return $this;
175
    }
176
177
    /**
178
     * Getter for restrictedPackageName.
179
     *
180
     * @return string
181
     */
182
    public function getRestrictedPackageName()
183
    {
184
        return $this->restrictedPackageName;
185
    }
186
187
    /**
188
     * Setter for restrictedPackageName.
189
     *
190
     * @param string $restrictedPackageName Package name of the application.
191
     * @return $this
192
     * @throws \ker0x\Push\Adapter\Fcm\Message\Exception\InvalidOptionsException
193
     */
194
    public function setRestrictedPackageName($restrictedPackageName)
195
    {
196
        if (!is_string($restrictedPackageName)) {
197
            throw InvalidOptionsException::mustBeString('restricted_package_name');
198
        }
199
        $this->restrictedPackageName = $restrictedPackageName;
200
201
        return $this;
202
    }
203
204
    /**
205
     * Getter for dryRun.
206
     *
207
     * @return bool
208
     */
209
    public function isDryRun()
210
    {
211
        return $this->dryRun;
212
    }
213
214
    /**
215
     * Setter for dryRun.
216
     *
217
     * @param bool $dryRun Test a request without sending a message if set to `true`.
218
     * @return $this
219
     * @throws \ker0x\Push\Adapter\Fcm\Message\Exception\InvalidOptionsException
220
     */
221
    public function setDryRun($dryRun)
222
    {
223
        if (!is_bool($dryRun)) {
224
            throw InvalidOptionsException::mustBeBool('dry_run');
225
        }
226
        $this->dryRun = $dryRun;
227
228
        return $this;
229
    }
230
}
231