Completed
Pull Request — master (#3)
by Massimiliano
04:24
created

Sms::getText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Fazland\SkebbyRestClient\DataStructure;
4
5
use Fazland\SkebbyRestClient\Constant\ValidityPeriods;
6
use Fazland\SkebbyRestClient\Exception\InvalidDeliveryStartException;
7
use Fazland\SkebbyRestClient\Exception\InvalidValidityPeriodException;
8
9
/**
10
 * @author Massimiliano Braglia <[email protected]>
11
 */
12
class Sms
13
{
14
    /**
15
     * @var string
16
     */
17
    private $sender;
18
19
    /**
20
     * @var string[]
21
     */
22
    private $recipients;
23
24
    /**
25
     * @var string[][]
26
     */
27
    private $recipientVariables;
28
29
    /**
30
     * @var string
31
     */
32
    private $text;
33
34
    /**
35
     * @var string
36
     */
37
    private $userReference;
38
39
    /**
40
     * @var \DateTime
41
     */
42
    private $deliveryStart;
43
44
    /**
45
     * @var \DateInterval
46
     */
47
    private $validityPeriod;
48
49
    /**
50
     * Sms constructor.
51
     */
52 14
    public function __construct()
53
    {
54 14
        $this->recipients = [];
55 14
        $this->recipientVariables = [];
56 14
    }
57
58
    /**
59
     * @return static
60
     */
61 9
    public static function create()
62
    {
63 9
        return new static();
64
    }
65
66
    /**
67
     * @return string
68
     */
69 8
    public function getSender()
70
    {
71 8
        return $this->sender;
72
    }
73
74
    /**
75
     * @param string $sender
76
     *
77
     * @return $this
78
     */
79 1
    public function setSender($sender)
80
    {
81 1
        $this->sender = $sender;
82
83 1
        return $this;
84
    }
85
86
    /**
87
     * @return string[]
88
     */
89 9
    public function getRecipients()
90
    {
91 9
        return $this->recipients;
92
    }
93
94
    /**
95
     * @param string[] $recipients
96
     *
97
     * @return $this
98
     */
99 8
    public function setRecipients(array $recipients)
100
    {
101 8
        $this->recipients = $recipients;
102
103 8
        return $this;
104
    }
105
106
    /**
107
     * @param string $recipient
108
     *
109
     * @return $this
110
     */
111 6
    public function addRecipient($recipient)
112
    {
113 6
        $this->recipients[] = $recipient;
114
115 6
        return $this;
116
    }
117
118
    /**
119
     * @param string $recipient
120
     *
121
     * @return $this
122
     */
123 1
    public function removeRecipient($recipient)
124
    {
125 1
        $itemPosition = array_search($recipient, $this->recipients);
126
127 1
        if (false !== $itemPosition) {
128 1
            unset($this->recipients[$itemPosition]);
129 1
        }
130
131 1
        unset($this->recipientVariables[$recipient]);
132
133 1
        return $this;
134
    }
135
136
    /**
137
     * @return bool
138
     */
139 9
    public function hasRecipients()
140
    {
141 9
        return ! empty($this->recipients);
142
    }
143
144
    /**
145
     * @return string[][]
146
     */
147 10
    public function getRecipientVariables()
148
    {
149 10
        return $this->recipientVariables;
150
    }
151
152
    /**
153
     * @param string $recipient
154
     * @param string[] $recipientVariables
155
     *
156
     * @return $this
157
     */
158 1
    public function setRecipientVariables($recipient, array $recipientVariables)
159
    {
160 1
        $this->recipientVariables[$recipient] = $recipientVariables;
161
162 1
        return $this;
163
    }
164
165
    /**
166
     * @param string $recipient
167
     * @param string $recipientVariable
168
     * @param string $recipientVariableValue
169
     *
170
     * @return $this
171
     */
172 5
    public function addRecipientVariable($recipient, $recipientVariable, $recipientVariableValue)
173
    {
174 5
        if (! isset($this->recipientVariables[$recipient])) {
175 5
            $this->recipientVariables[$recipient] = [];
176 5
        }
177
178 5
        $this->recipientVariables[$recipient][$recipientVariable] = $recipientVariableValue;
179
180 5
        return $this;
181
    }
182
183
    /**
184
     * @param string $recipient
185
     * @param string $recipientVariable
186
     *
187
     * @return $this
188
     */
189 1
    public function removeRecipientVariable($recipient, $recipientVariable)
190
    {
191 1
        unset($this->recipientVariables[$recipient][$recipientVariable]);
192
193 1
        return $this;
194
    }
195
196
    /**
197
     * @return bool
198
     */
199 8
    public function hasRecipientVariables()
200
    {
201 8
        return ! empty($this->recipientVariables);
202
    }
203
204
    /**
205
     * @return $this
206
     */
207 8
    public function clearRecipientVariables()
208
    {
209 8
        $this->recipientVariables = [];
210
211 8
        return $this;
212
    }
213
214
    /**
215
     * @return string
216
     */
217 8
    public function getText()
218
    {
219 8
        return $this->text;
220
    }
221
222
    /**
223
     * @param string $text
224
     *
225
     * @return $this
226
     */
227 9
    public function setText($text)
228
    {
229 9
        $this->text = $text;
230
231 9
        return $this;
232
    }
233
234
    /**
235
     * @return string
236
     */
237 8
    public function getUserReference()
238
    {
239 8
        return $this->userReference;
240
    }
241
242
    /**
243
     * @param string $userReference
244
     *
245
     * @return $this
246
     */
247 1
    public function setUserReference($userReference)
248
    {
249 1
        $this->userReference = $userReference;
250
251 1
        return $this;
252
    }
253
254
    /**
255
     * @return \DateTime
256
     */
257 8
    public function getDeliveryStart()
258
    {
259 8
        return $this->deliveryStart;
260
    }
261
262
    /**
263
     * @param \DateTime|null $deliveryStart
264
     *
265
     * @return $this
266
     *
267
     * @throws InvalidDeliveryStartException
268
     */
269 3
    public function setDeliveryStart(\DateTime $deliveryStart = null)
270
    {
271 3
        if (null !== $deliveryStart && $deliveryStart < date_create_from_format('U', (string)time())) {
272 1
            throw new InvalidDeliveryStartException();
273
        }
274
275 2
        $this->deliveryStart = $deliveryStart;
276
277 2
        return $this;
278
    }
279
280
    /**
281
     * @return \DateInterval
282
     */
283 8
    public function getValidityPeriod()
284
    {
285 8
        return $this->validityPeriod;
286
    }
287
288
    /**
289
     * @param \DateInterval|null $validityPeriod
290
     *
291
     * @return $this
292
     *
293
     * @throws InvalidValidityPeriodException
294
     */
295 3
    public function setValidityPeriod(\DateInterval $validityPeriod = null)
296
    {
297 3
        if (null !== $validityPeriod &&
298 3
            ($validityPeriod->i < ValidityPeriods::MIN || $validityPeriod->i > ValidityPeriods::MAX)
299 3
        ) {
300 1
            throw new InvalidValidityPeriodException();
301
        }
302
303 2
        $this->validityPeriod = $validityPeriod;
304
305 2
        return $this;
306
    }
307
}
308