Code Duplication    Length = 28-28 lines in 2 locations

src/Charcoal/User/AbstractUser.php 2 locations

@@ 217-244 (lines=28) @@
214
     * @throws InvalidArgumentException If the ts is not a valid date/time.
215
     * @return self
216
     */
217
    public function setLastLoginDate($lastLoginDate)
218
    {
219
        if ($lastLoginDate === null) {
220
            $this->lastLoginDate = null;
221
            return $this;
222
        }
223
224
        if (is_string($lastLoginDate)) {
225
            try {
226
                $lastLoginDate = new DateTime($lastLoginDate);
227
            } catch (Exception $e) {
228
                throw new InvalidArgumentException(sprintf(
229
                    'Invalid login date (%s)',
230
                    $e->getMessage()
231
                ), 0, $e);
232
            }
233
        }
234
235
        if (!($lastLoginDate instanceof DateTimeInterface)) {
236
            throw new InvalidArgumentException(
237
                'Invalid "Last Login Date" value. Must be a date/time string or a DateTime object.'
238
            );
239
        }
240
241
        $this->lastLoginDate = $lastLoginDate;
242
243
        return $this;
244
    }
245
246
    /**
247
     * @return DateTimeInterface|null
@@ 296-323 (lines=28) @@
293
     * @throws InvalidArgumentException If the passsword date is not a valid DateTime.
294
     * @return self
295
     */
296
    public function setLastPasswordDate($lastPasswordDate)
297
    {
298
        if ($lastPasswordDate === null) {
299
            $this->lastPasswordDate = null;
300
            return $this;
301
        }
302
303
        if (is_string($lastPasswordDate)) {
304
            try {
305
                $lastPasswordDate = new DateTime($lastPasswordDate);
306
            } catch (Exception $e) {
307
                throw new InvalidArgumentException(sprintf(
308
                    'Invalid last password date (%s)',
309
                    $e->getMessage()
310
                ), 0, $e);
311
            }
312
        }
313
314
        if (!($lastPasswordDate instanceof DateTimeInterface)) {
315
            throw new InvalidArgumentException(
316
                'Invalid "Last Password Date" value. Must be a date/time string or a DateTime object.'
317
            );
318
        }
319
320
        $this->lastPasswordDate = $lastPasswordDate;
321
322
        return $this;
323
    }
324
325
    /**
326
     * @return DateTimeInterface|null