Code Duplication    Length = 20-21 lines in 3 locations

src/Charcoal/User/AbstractAuthToken.php 1 location

@@ 130-149 (lines=20) @@
127
     * @throws InvalidArgumentException If the date/time is invalid.
128
     * @return self
129
     */
130
    public function setExpiry($expiry)
131
    {
132
        if ($expiry === null) {
133
            $this->expiry = null;
134
            return $this;
135
        }
136
137
        if (is_string($expiry)) {
138
            $expiry = new DateTime($expiry);
139
        }
140
141
        if (!($expiry instanceof DateTimeInterface)) {
142
            throw new InvalidArgumentException(
143
                'Invalid "Expiry" value. Must be a date/time string or a DateTime object.'
144
            );
145
        }
146
147
        $this->expiry = $expiry;
148
        return $this;
149
    }
150
151
    /**
152
     * @return DateTimeInterface|null

src/Charcoal/User/AbstractUser.php 2 locations

@@ 259-279 (lines=21) @@
256
     * @throws InvalidArgumentException If the IP is not an IP string, an integer, or null.
257
     * @return self
258
     */
259
    public function setLastLoginIp($ip)
260
    {
261
        if ($ip === null) {
262
            $this->lastLoginIp = null;
263
            return $this;
264
        }
265
266
        if (is_int($ip)) {
267
            $ip = long2ip($ip);
268
        }
269
270
        if (!is_string($ip)) {
271
            throw new InvalidArgumentException(
272
                'Invalid IP address'
273
            );
274
        }
275
276
        $this->lastLoginIp = $ip;
277
278
        return $this;
279
    }
280
281
    /**
282
     * Get the last login IP in x.x.x.x format
@@ 338-358 (lines=21) @@
335
     * @throws InvalidArgumentException If the IP is not null, an integer or an IP string.
336
     * @return self
337
     */
338
    public function setLastPasswordIp($ip)
339
    {
340
        if ($ip === null) {
341
            $this->lastPasswordIp = null;
342
            return $this;
343
        }
344
345
        if (is_int($ip)) {
346
            $ip = long2ip($ip);
347
        }
348
349
        if (!is_string($ip)) {
350
            throw new InvalidArgumentException(
351
                'Invalid IP address'
352
            );
353
        }
354
355
        $this->lastPasswordIp = $ip;
356
357
        return $this;
358
    }
359
360
    /**
361
     * Get the last password change IP in x.x.x.x format