Completed
Push — master ( 9a9a39...cf3017 )
by Maximilian
03:39
created

PendingActivation::getKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sententiaregum project.
5
 *
6
 * (c) Maximilian Bosch <[email protected]>
7
 * (c) Ben Bieler <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace AppBundle\Model\User;
14
15
use DateTime;
16
use Doctrine\ORM\Mapping as ORM;
17
18
/**
19
 * Model that represents the internal activation life cycle during the user approval.
20
 *
21
 * @author Maximilian Bosch <[email protected]>
22
 * @ORM\Embeddable
23
 */
24
class PendingActivation implements \Serializable
25
{
26
    /**
27
     * @var DateTime
28
     *
29
     * @ORM\Column(name="activation_date", type="datetime", nullable=true)
30
     */
31
    private $activationDate;
32
33
    /**
34
     * @var string
35
     *
36
     * @ORM\Column(name="key", type="string", nullable=true)
37
     */
38
    private $key;
39
40
    /**
41
     * Constructor.
42
     *
43
     * @param DateTime $activationDate
44
     * @param string   $key
45
     */
46
    public function __construct(DateTime $activationDate, $key = null)
47
    {
48
        $this->activationDate = $activationDate;
49
        $this->key            = $key;
50
    }
51
52
    /**
53
     * Checks if the activation is expired.
54
     *
55
     * @throws \LogicException If the activation is missing
56
     *
57
     * @return bool
58
     */
59
    public function isActivationExpired()
60
    {
61
        return time() - $this->activationDate->getTimestamp() >= 3600 * 2;
62
    }
63
64
    /**
65
     * Set key.
66
     *
67
     * @param string $key
68
     *
69
     * @return $this
70
     */
71
    public function setKey($key)
72
    {
73
        $this->key = (string) $key;
74
75
        return $this;
76
    }
77
78
    /**
79
     * Get key.
80
     *
81
     * @return string
82
     */
83
    public function getKey()
84
    {
85
        return $this->key;
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function serialize()
92
    {
93
        return serialize([
94
            $this->key,
95
            $this->activationDate,
96
        ]);
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function unserialize($serialized)
103
    {
104
        list($this->key, $this->activationDate) = unserialize($serialized);
105
    }
106
}
107