Completed
Push — master ( 4f5859...1ec913 )
by Artem
08:29
created

Model/ExpireAccountTrait.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
//----------------------------------------------------------------------
4
//
5
//  Copyright (C) 2017 Artem Rodygin
6
//
7
//  You should have received a copy of the MIT License along with
8
//  this file. If not, see <http://opensource.org/licenses/MIT>.
9
//
10
//----------------------------------------------------------------------
11
12
namespace Pignus\Model;
13
14
use Doctrine\ORM\Mapping as ORM;
15
16
/**
17
 * Trait for "account expiration" feature.
18
 */
19 View Code Duplication
trait ExpireAccountTrait
0 ignored issues
show
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 1
    public function expireAccountAt(\DateTime $time = null)
36
    {
37 1
        if ($this->canAccountBeExpired()) {
38 1
            $this->accountExpiresAt = $time === null ? null : $time->getTimestamp();
39
        }
40
41 1
        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 1
    public function expireAccountIn(\DateInterval $interval)
52
    {
53 1
        if ($this->canAccountBeExpired()) {
54 1
            $this->accountExpiresAt = date_create()->add($interval)->getTimestamp();
55
        }
56
57 1
        return $this;
58
    }
59
60
    /**
61
     * Specifies whether the "account expiration" feature is available for this user.
62
     *
63
     * @return bool
64
     */
65 2
    protected function canAccountBeExpired(): bool
66
    {
67 2
        return true;
68
    }
69
}
70