Code Duplication    Length = 28-29 lines in 3 locations

src/Charcoal/Object/ObjectSchedule.php 2 locations

@@ 219-247 (lines=29) @@
216
     * @throws InvalidArgumentException If the date/time is invalid.
217
     * @return ObjectScheduleInterface Chainable
218
     */
219
    public function setScheduledDate($ts)
220
    {
221
        if ($ts === null) {
222
            $this->scheduledDate = null;
223
            return $this;
224
        }
225
226
        if (is_string($ts)) {
227
            try {
228
                $ts = new DateTime($ts);
229
            } catch (Exception $e) {
230
                throw new InvalidArgumentException(sprintf(
231
                    '%s (%s)',
232
                    $e->getMessage(),
233
                    $ts
234
                ), 0, $e);
235
            }
236
        }
237
238
        if (!($ts instanceof DateTimeInterface)) {
239
            throw new InvalidArgumentException(
240
                'Invalid "Processing Date" value. Must be a date/time string or a DateTime object.'
241
            );
242
        }
243
244
        $this->scheduledDate = $ts;
245
246
        return $this;
247
    }
248
249
    /**
250
     * Retrieve the date/time the item should be processed at.
@@ 266-294 (lines=29) @@
263
     * @throws InvalidArgumentException If the date/time is invalid.
264
     * @return ObjectScheduleInterface Chainable
265
     */
266
    public function setProcessedDate($ts)
267
    {
268
        if ($ts === null) {
269
            $this->processedDate = null;
270
            return $this;
271
        }
272
273
        if (is_string($ts)) {
274
            try {
275
                $ts = new DateTime($ts);
276
            } catch (Exception $e) {
277
                throw new InvalidArgumentException(sprintf(
278
                    '%s (%s)',
279
                    $e->getMessage(),
280
                    $ts
281
                ), 0, $e);
282
            }
283
        }
284
285
        if (!($ts instanceof DateTimeInterface)) {
286
            throw new InvalidArgumentException(
287
                'Invalid "Processed Date" value. Must be a date/time string or a DateTime object.'
288
            );
289
        }
290
291
        $this->processedDate = $ts;
292
293
        return $this;
294
    }
295
296
    /**
297
     * Retrieve the date/time the item was processed at.

src/Charcoal/Object/UserData.php 1 location

@@ 203-230 (lines=28) @@
200
     * @throws InvalidArgumentException If the timestamp is invalid.
201
     * @return UserDataInterface Chainable
202
     */
203
    public function setTs($timestamp)
204
    {
205
        if ($timestamp === null) {
206
            $this->ts = null;
207
            return $this;
208
        }
209
210
        if (is_string($timestamp)) {
211
            try {
212
                $timestamp = new DateTime($timestamp);
213
            } catch (Exception $e) {
214
                throw new InvalidArgumentException(sprintf(
215
                    'Invalid timestamp: %s',
216
                    $e->getMessage()
217
                ), 0, $e);
218
            }
219
        }
220
221
        if (!$timestamp instanceof DateTimeInterface) {
222
            throw new InvalidArgumentException(
223
                'Invalid timestamp value. Must be a date/time string or a DateTime object.'
224
            );
225
        }
226
227
        $this->ts = $timestamp;
228
229
        return $this;
230
    }
231
232
    /**
233
     * Retrieve the creation timestamp.