Completed
Push — master ( 8b8003...277c4a )
by
unknown
10s
created

UserTrait::isPasswordRequestNonExpired()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
3
namespace Smart\AuthenticationBundle\Entity\User;
4
5
use DateTime;
6
use Doctrine\ORM\Mapping as ORM;
7
use Symfony\Component\Validator\Constraints as Assert;
8
9
/**
10
 * Basic methods to implements Symfony\Component\Security\Core\User\UserInterface
11
 *
12
 * @author Nicolas Bastien <[email protected]>
13
 */
14
trait UserTrait
15
{
16
    /**
17
     * @var string
18
     *
19
     * @ORM\Column(type="string", length=255, nullable=false, unique=true)
20
     *
21
     * @Assert\NotBlank
22
     * @Assert\Email
23
     */
24
    private $email;
25
26
    /**
27
     * @var string
28
     *
29
     * @ORM\Column(name="password", type="string", length=100, nullable=false)
30
     */
31
    private $password;
32
33
    /**
34
     * @var string
35
     */
36
    private $plainPassword;
37
38
    /**
39
     * @var string
40
     *
41
     * @ORM\Column(type="string", length=255, nullable=true)
42
     */
43
    protected $firstName;
44
45
    /**
46
     * @var string
47
     *
48
     * @ORM\Column(type="string", length=255, nullable=true)
49
     */
50
    protected $lastName;
51
52
    /**
53
     * @var array
54
     *
55
     * @ORM\Column(type="json_array")
56
     */
57
    private $roles;
58
59
    /**
60
     * @return string
61
     */
62
    public function __toString()
63
    {
64
        if (strlen(trim($this->getFullName())) > 0) {
65
            return (string) $this->getFullName();
66
        }
67
68
        return (string) $this->getEmail();
69
    }
70
71
    /**
72
     * On list we want to be able to sort by Lastname
73
     * @return string
74
     */
75
    public function getListDisplay()
76
    {
77
        if (strlen(trim($this->getLastName())) > 0) {
78
            return (string) $this->getListFullName();
79
        }
80
81
        return (string) $this->getEmail();
82
    }
83
84
    /**
85
     * @return int
86
     */
87
    public function getId()
88
    {
89
        return $this->id;
0 ignored issues
show
Bug introduced by
The property id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
90
    }
91
92
    /**
93
     * @inheritdoc
94
     */
95
    public function getUsername()
96
    {
97
        return $this->email;
98
    }
99
100
    /**
101
     * @inheritdoc
102
     */
103
    public function getEmail()
104
    {
105
        return $this->email;
106
    }
107
108
    /**
109
     * @param string $email
110
     *
111
     * @return $this
112
     */
113
    public function setEmail($email)
114
    {
115
        $this->email = $email;
116
117
        return $this;
118
    }
119
120
    /**
121
     * @inheritdoc
122
     */
123
    public function getPassword()
124
    {
125
        return $this->password;
126
    }
127
128
    /**
129
     * @param string $password
130
     *
131
     * @return $this
132
     */
133
    public function setPassword($password)
134
    {
135
        $this->password = $password;
136
137
        return $this;
138
    }
139
140
    /**
141
     * @inheritdoc
142
     */
143
    public function getSalt()
144
    {
145
        return null;
146
    }
147
148
    /**
149
     * @return string
150
     */
151
    public function getPlainPassword()
152
    {
153
        return $this->plainPassword;
154
    }
155
156
    /**
157
     * @param string $plainPassword
158
     *
159
     * @return $this
160
     */
161
    public function setPlainPassword($plainPassword)
162
    {
163
        $this->plainPassword = $plainPassword;
164
165
        return $this;
166
    }
167
168
    /**
169
     * @inheritdoc
170
     */
171
    public function eraseCredentials()
172
    {
173
        $this->plainPassword = null;
174
175
        return;
176
    }
177
    
178
    /**
179
     * @inheritdoc
180
     */
181
    public function getRoles()
182
    {
183
        return $this->roles;
184
    }
185
186
    /**
187
     * @param array $roles
188
     *
189
     * @return $this
190
     */
191
    public function setRoles(array $roles = [])
192
    {
193
        $this->roles = $roles;
194
195
        return $this;
196
    }
197
198
    /**
199
     * @return string
200
     */
201
    public function getFirstName()
202
    {
203
        return $this->firstName;
204
    }
205
206
    /**
207
     * @param string $firstName
208
     *
209
     * @return $this
210
     */
211
    public function setFirstName($firstName)
212
    {
213
        $this->firstName = $firstName;
214
215
        return $this;
216
    }
217
218
    /**
219
     * @return string
220
     */
221
    public function getLastName()
222
    {
223
        return $this->lastName;
224
    }
225
226
    /**
227
     * @param string $lastName
228
     *
229
     * @return $this
230
     */
231
    public function setLastName($lastName)
232
    {
233
        $this->lastName = $lastName;
234
235
        return $this;
236
    }
237
238
    /**
239
     * @return string
240
     */
241
    public function getFullName()
242
    {
243
        return sprintf('%s %s', (string)$this->getFirstName(), (string)$this->getLastName());
244
    }
245
246
    /**
247
     * @return string
248
     */
249
    public function getListFullName()
250
    {
251
        return sprintf('%s %s', (string)$this->getLastName(), (string)$this->getFirstName());
252
    }
253
254
    /**
255
     * @return string
256
     */
257
    public function getFullNameAndEmail()
258
    {
259
        if (strlen(trim($this->getFullName())) > 0) {
260
            return sprintf('%s - %s', $this->getFullName(), $this->getEmail());
261
        }
262
263
        return $this->getEmail();
264
    }
265
266
    /**
267
     * @see \Serializable::serialize()
268
     */
269
    public function serialize()
270
    {
271
        return serialize(array(
272
            $this->id,
273
            $this->email,
274
            $this->password,
275
        ));
276
    }
277
278
    /**
279
     * @see \Serializable::unserialize()
280
     */
281
    public function unserialize($serialized)
282
    {
283
        list (
284
            $this->id,
285
            $this->email,
286
            $this->password,
287
            // see section on salt below
288
            // $this->salt
289
            ) = unserialize($serialized);
290
    }
291
}
292