Code Duplication    Length = 27-27 lines in 4 locations

src/Charcoal/Queue/QueueItemTrait.php 4 locations

@@ 187-213 (lines=27) @@
184
     * @throws InvalidArgumentException If the date/time is invalid.
185
     * @return self
186
     */
187
    public function setQueuedDate($ts)
188
    {
189
        if ($ts === null) {
190
            $this->queuedDate = null;
191
            return $this;
192
        }
193
194
        if (is_string($ts)) {
195
            try {
196
                $ts = new DateTime($ts);
197
            } catch (Exception $e) {
198
                throw new InvalidArgumentException(
199
                    sprintf('Can not set queued date: %s', $e->getMessage())
200
                );
201
            }
202
        }
203
204
        if (!($ts instanceof DateTimeInterface)) {
205
            throw new InvalidArgumentException(
206
                'Invalid "Queued Date" value. Must be a date/time string or a DateTime object.'
207
            );
208
        }
209
210
        $this->queuedDate = $ts;
211
212
        return $this;
213
    }
214
215
    /**
216
     * Retrieve the date/time the item was queued at.
@@ 232-258 (lines=27) @@
229
     * @throws InvalidArgumentException If the date/time is invalid.
230
     * @return self
231
     */
232
    public function setProcessingDate($ts)
233
    {
234
        if ($ts === null) {
235
            $this->processingDate = null;
236
            return $this;
237
        }
238
239
        if (is_string($ts)) {
240
            try {
241
                $ts = new DateTime($ts);
242
            } catch (Exception $e) {
243
                throw new InvalidArgumentException(
244
                    sprintf('%s (%s)', $e->getMessage(), $ts)
245
                );
246
            }
247
        }
248
249
        if (!($ts instanceof DateTimeInterface)) {
250
            throw new InvalidArgumentException(
251
                'Invalid "Processing Date" value. Must be a date/time string or a DateTime object.'
252
            );
253
        }
254
255
        $this->processingDate = $ts;
256
257
        return $this;
258
    }
259
260
    /**
261
     * Retrieve the date/time the item should be processed at.
@@ 277-303 (lines=27) @@
274
     * @throws InvalidArgumentException If the date/time is invalid.
275
     * @return self
276
     */
277
    public function setProcessedDate($ts)
278
    {
279
        if ($ts === null) {
280
            $this->processedDate = null;
281
            return $this;
282
        }
283
284
        if (is_string($ts)) {
285
            try {
286
                $ts = new DateTime($ts);
287
            } catch (Exception $e) {
288
                throw new InvalidArgumentException(
289
                    sprintf('%s (%s)', $e->getMessage(), $ts)
290
                );
291
            }
292
        }
293
294
        if (!($ts instanceof DateTimeInterface)) {
295
            throw new InvalidArgumentException(
296
                'Invalid "Processed Date" value. Must be a date/time string or a DateTime object.'
297
            );
298
        }
299
300
        $this->processedDate = $ts;
301
302
        return $this;
303
    }
304
305
    /**
306
     * Retrieve the date/time the item was processed at.
@@ 332-358 (lines=27) @@
329
     * @throws InvalidArgumentException If the date/time is invalid.
330
     * @return self
331
     */
332
    public function setExpiryDate($ts)
333
    {
334
        if ($ts === null) {
335
            $this->expiryDate = null;
336
            return $this;
337
        }
338
339
        if (is_string($ts)) {
340
            try {
341
                $ts = new DateTime($ts);
342
            } catch (Exception $e) {
343
                throw new InvalidArgumentException(
344
                    sprintf('%s (%s)', $e->getMessage(), $ts)
345
                );
346
            }
347
        }
348
349
        if (!($ts instanceof DateTimeInterface)) {
350
            throw new InvalidArgumentException(
351
                'Invalid "Expiry Date" value. Must be a date/time string or a DateTime object.'
352
            );
353
        }
354
355
        $this->expiryDate = $ts;
356
357
        return $this;
358
    }
359
360
    /**
361
     * @return string