Completed
Branch develop (f935f6)
by Romain
01:43
created

OptionsBuilder::setDryRun()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
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
     * @var null|string
15
     */
16
    protected $collapseKey;
17
18
    /**
19
     * @var null|string
20
     */
21
    protected $priority;
22
23
    /**
24
     * @var bool
25
     */
26
    protected $contentAvailable = false;
27
28
    /**
29
     * @var null|int
30
     */
31
    protected $timeToLive;
32
33
    /**
34
     * @var null|string
35
     */
36
    protected $restrictedPackageName;
37
38
    /**
39
     * @var bool
40
     */
41
    protected $dryRun = false;
42
43
    /**
44
     * @return string
45
     */
46
    public function getCollapseKey()
47
    {
48
        return $this->collapseKey;
49
    }
50
51
    /**
52
     * @param string $collapseKey
53
     * @return $this
54
     * @throws \ker0x\Push\Adapter\Fcm\Message\Exception\InvalidOptionsException
55
     */
56
    public function setCollapseKey($collapseKey)
57
    {
58
        if (!is_string($collapseKey)) {
59
            throw InvalidOptionsException::mustBeString('collapse_key');
60
        }
61
        $this->collapseKey = $collapseKey;
62
63
        return $this;
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getPriority()
70
    {
71
        return $this->priority;
72
    }
73
74
    /**
75
     * @param string $priority
76
     * @return $this
77
     */
78
    public function setPriority($priority)
79
    {
80
        $this->priority = $priority;
81
82
        return $this;
83
    }
84
85
    /**
86
     * @return boolean
87
     */
88
    public function isContentAvailable()
89
    {
90
        return $this->contentAvailable;
91
    }
92
93
    /**
94
     * @param boolean $contentAvailable
95
     * @return $this
96
     * @throws \ker0x\Push\Adapter\Fcm\Message\Exception\InvalidOptionsException
97
     */
98
    public function setContentAvailable($contentAvailable)
99
    {
100
        if (!is_bool($contentAvailable)) {
101
            throw InvalidOptionsException::mustBeBool('content_available');
102
        }
103
        $this->contentAvailable = $contentAvailable;
104
105
        return $this;
106
    }
107
108
    /**
109
     * @return string
110
     */
111
    public function getTimeToLive()
112
    {
113
        return $this->timeToLive;
114
    }
115
116
    /**
117
     * @param int $timeToLive
118
     * @return $this
119
     * @throws \ker0x\Push\Adapter\Fcm\Message\Exception\InvalidOptionsException
120
     */
121
    public function setTimeToLive($timeToLive)
122
    {
123
        if (!is_int($timeToLive) || $timeToLive < 0 || $timeToLive > 2419200) {
124
            throw InvalidOptionsException::invalidTTL($timeToLive);
125
        }
126
        $this->timeToLive = $timeToLive;
127
128
        return $this;
129
    }
130
131
    /**
132
     * @return string
133
     */
134
    public function getRestrictedPackageName()
135
    {
136
        return $this->restrictedPackageName;
137
    }
138
139
    /**
140
     * @param string $restrictedPackageName
141
     * @return $this
142
     * @throws \ker0x\Push\Adapter\Fcm\Message\Exception\InvalidOptionsException
143
     */
144
    public function setRestrictedPackageName($restrictedPackageName)
145
    {
146
        if (!is_string($restrictedPackageName)) {
147
            throw InvalidOptionsException::mustBeString('restricted_package_name');
148
        }
149
        $this->restrictedPackageName = $restrictedPackageName;
150
151
        return $this;
152
    }
153
154
    /**
155
     * @return boolean
156
     */
157
    public function isDryRun()
158
    {
159
        return $this->dryRun;
160
    }
161
162
    /**
163
     * @param boolean $dryRun
164
     * @return $this
165
     * @throws \ker0x\Push\Adapter\Fcm\Message\Exception\InvalidOptionsException
166
     */
167
    public function setDryRun($dryRun)
168
    {
169
        if (!is_bool($dryRun)) {
170
            throw InvalidOptionsException::mustBeBool('dry_run');
171
        }
172
        $this->dryRun = $dryRun;
173
174
        return $this;
175
    }
176
}
177