Code Duplication    Length = 51-51 lines in 2 locations

Model/ExpireAccountTrait.php 1 location

@@ 19-69 (lines=51) @@
16
/**
17
 * Trait for "account expiration" feature.
18
 */
19
trait ExpireAccountTrait
20
{
21
    /**
22
     * @var int Unix Epoch timestamp when the account expires.
23
     *
24
     * @ORM\Column(name="account_expires_at", type="integer", nullable=true)
25
     */
26
    protected $accountExpiresAt;
27
28
    /**
29
     * Makes account to expire at specified moment of time (NULL for no expiration).
30
     *
31
     * @param \DateTime $time
32
     *
33
     * @return self
34
     */
35
    public function expireAccountAt(\DateTime $time = null)
36
    {
37
        if ($this->canAccountBeExpired()) {
38
            $this->accountExpiresAt = $time === null ? null : $time->getTimestamp();
39
        }
40
41
        return $this;
42
    }
43
44
    /**
45
     * Makes account to expire in specified period of time.
46
     *
47
     * @param \DateInterval $interval
48
     *
49
     * @return self
50
     */
51
    public function expireAccountIn(\DateInterval $interval)
52
    {
53
        if ($this->canAccountBeExpired()) {
54
            $this->accountExpiresAt = date_create()->add($interval)->getTimestamp();
55
        }
56
57
        return $this;
58
    }
59
60
    /**
61
     * Specifies whether the "account expiration" feature is available for this user.
62
     *
63
     * @return bool
64
     */
65
    protected function canAccountBeExpired(): bool
66
    {
67
        return true;
68
    }
69
}
70

Model/ExpirePasswordTrait.php 1 location

@@ 19-69 (lines=51) @@
16
/**
17
 * Trait for "password expiration" feature.
18
 */
19
trait ExpirePasswordTrait
20
{
21
    /**
22
     * @var int Unix Epoch timestamp when the password expires.
23
     *
24
     * @ORM\Column(name="password_expires_at", type="integer", nullable=true)
25
     */
26
    protected $passwordExpiresAt;
27
28
    /**
29
     * Makes password to expire at specified moment of time (NULL for no expiration).
30
     *
31
     * @param \DateTime $time
32
     *
33
     * @return self
34
     */
35
    public function expirePasswordAt(\DateTime $time = null)
36
    {
37
        if ($this->canPasswordBeExpired()) {
38
            $this->passwordExpiresAt = $time === null ? null : $time->getTimestamp();
39
        }
40
41
        return $this;
42
    }
43
44
    /**
45
     * Makes password to expire in specified period of time.
46
     *
47
     * @param \DateInterval $interval
48
     *
49
     * @return self
50
     */
51
    public function expirePasswordIn(\DateInterval $interval)
52
    {
53
        if ($this->canPasswordBeExpired()) {
54
            $this->passwordExpiresAt = date_create()->add($interval)->getTimestamp();
55
        }
56
57
        return $this;
58
    }
59
60
    /**
61
     * Specifies whether the "password expiration" feature is available for this user.
62
     *
63
     * @return bool
64
     */
65
    protected function canPasswordBeExpired(): bool
66
    {
67
        return true;
68
    }
69
}
70