Completed
Branch develop (b9c805)
by Pavel
06:33
created

User::setHash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
8
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
9
use Symfony\Component\Validator\Constraints as Assert;
10
11
/**
12
 * User
13
 *
14
 * @ORM\Table(name="user")
15
 * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
16
 * @UniqueEntity(fields="email", message="Email already taken")
17
 */
18
class User implements AdvancedUserInterface, \JsonSerializable
19
{
20
    const ROLE_ADMIN = 'ROLE_ADMIN';
21
    const ROLE_USER = 'ROLE_USER';
22
23
    /**
24
     * @ORM\Id
25
     * @ORM\GeneratedValue
26
     * @ORM\Column(type="integer")
27
     */
28
    private $id;
29
30
    /**
31
     * @ORM\Column(type="string", unique=true)
32
     * @Assert\NotBlank()
33
     * @Assert\Email()
34
     */
35
    private $email;
36
37
    /**
38
     * @ORM\Column(type="string", length=40)
39
     * @Assert\Length(min="1", minMessage="This field can not be less than 1 character")
40
     */
41
    private $firstName;
42
43
    /**
44
     * @ORM\Column(type="string", length=40)
45
     * @Assert\Length(min="1", minMessage="This field can not be less than 1 character")
46
     */
47
    private $lastName;
48
49
    /**
50
     * @ORM\Column(type="string", length=64, nullable=true)
51
     */
52
    private $password;
53
54
    /**
55
     * @Assert\Length(max=4096)
56
     */
57
    private $plainPassword;
58
59
    /**
60
     * @ORM\Column(type="string", length=64)
61
     */
62
    private $role;
63
64
    /**
65
     * @ORM\Column(name="is_active", type="boolean")
66
     */
67
    private $isActive;
68
69
    /**
70
     * @var string
71
     *
72
     * @ORM\Column(name="fb_token", type="string", nullable=true)
73
     */
74
    protected $facebookToken;
75
    /**
76
     * @var string
77
     *
78
     * @ORM\Column(name="fb_id", type="string", nullable=true)
79
     */
80
    protected $facebookId;
81
    /**
82
     * @var string
83
     *
84
     * @ORM\Column(name="g_token", type="string", nullable=true)
85
     */
86
    protected $googleToken;
87
    /**
88
     * @var string
89
     *
90
     * @ORM\Column(name="g_id", type="string", nullable=true)
91
     */
92
    protected $googleId;
93
    /**
94
     * @var string
95
     *
96
     * @ORM\Column(name="type", type="string", nullable=true)
97
     */
98
    protected $type;
99
100
    /**
101
     * @ORM\Column(name="is_reg", type="boolean")
102
     */
103
    protected $isReg;
104
105
    /**
106
     * @ORM\Column(name="hash", type="string", nullable=true)
107
     */
108
    protected $hash;
109
110
    /**
111
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\ModuleUser", mappedBy="user")
112
     */
113
    private $modulesUser;
114
115
    public function jsonSerialize()
116
    {
117
        return [
118
            'firstName' => $this->getFirstName(),
119
            'lastName' => $this->getLastName(),
120
            'email' => $this->getEmail()
121
        ];
122
    }
123
124
125
    /**
126
     *
127
     */
128 27
    public function __construct()
129
    {
130 27
        $this->isActive = false;
131 27
        $this->isReg = false;
132 27
        $this->modulesUser = new ArrayCollection();
133 27
        $this->role = self::ROLE_USER;
134 27
    }
135
136
    /**
137
     * @return mixed
138
     */
139
    public function getModulesUser()
140
    {
141
        return $this->modulesUser;
142
    }
143
144
    /**
145
     * @param ModuleUser $moduleUser
146
     * @return $this
147
     */
148
    public function addModuleUser(ModuleUser $moduleUser)
149
    {
150
        $this->modulesUser->add($moduleUser);
151
152
        return $this;
153
    }
154
155
    /**
156
     * @param ModuleUser $moduleUser
157
     */
158
    public function removeModuleUser(ModuleUser $moduleUser)
159
    {
160
        $this->modulesUser->removeElement($moduleUser);
161
    }
162
163
    /**
164
     * @return mixed
165
     */
166 6
    public function getId()
167
    {
168 6
        return $this->id;
169
    }
170
171
    /**
172
     * {@inheritdoc}
173
     */
174
    public function getUsername()
175
    {
176
        return $this->getEmail();
177
    }
178
179
    /**
180
     * @return mixed
181
     */
182 4
    public function getEmail()
183
    {
184 4
        return $this->email;
185
    }
186
187
    /**
188
     * @param $email
189
     */
190 27
    public function setEmail($email)
191
    {
192 27
        $this->email = $email;
193
194 27
        return $this;
195
    }
196
197
    /**
198
     * @return mixed
199
     */
200 5
    public function getFirstName()
201
    {
202 5
        return $this->firstName;
203
    }
204
205
    /**
206
     * @param mixed $firstName
207
     */
208 27
    public function setFirstName($firstName)
209
    {
210 27
        $this->firstName = $firstName;
211
212 27
        return $this;
213
    }
214
215
    /**
216
     * @return mixed
217
     */
218 5
    public function getLastName()
219
    {
220 5
        return $this->lastName;
221
    }
222
223
    /**
224
     * @param mixed $lastName
225
     */
226 27
    public function setLastName($lastName)
227
    {
228 27
        $this->lastName = $lastName;
229
230 27
        return $this;
231
    }
232
233
    /**
234
     * {@inheritdoc}
235
     */
236 24
    public function getPassword()
237
    {
238 24
        return $this->password;
239
    }
240
241
    /**
242
     * @param $password
243
     */
244 27
    public function setPassword($password)
245
    {
246 27
        $this->password = $password;
247 27
    }
248
249
    /**
250
     * @param $role
251
     * @return $this
252
     */
253 27
    public function setRole($role)
254
    {
255 27
        $this->role = $role;
256
257 27
        return $this;
258
    }
259
260
    /**
261
     * @return mixed
262
     */
263
    public function getRole()
264
    {
265
        return $this->role;
266
    }
267
268
    /**
269
     * Returns the roles or permissions granted to the user for security.
270
     */
271 24
    public function getRoles()
272
    {
273 24
        return [$this->role];
274
275
    }
276
277
    /**
278
     * @return mixed
279
     */
280 1
    public function getPlainPassword()
281
    {
282 1
        return $this->plainPassword;
283
    }
284
285
    /**
286
     * @param $password
287
     */
288
    public function setPlainPassword($password)
289
    {
290
        $this->plainPassword = $password;
291
    }
292
293
    /**
294
     * Returns the salt that was originally used to encode the password.
295
     */
296 27
    public function getSalt()
297
    {
298
        // See "Do you need to use a Salt?" at http://symfony.com/doc/current/cookbook/security/entity_provider.html
299
        // we're using bcrypt in security.yml to encode the password, so
300
        // the salt value is built-in and you don't have to generate one
301
302 27
        return;
303
    }
304
305
    /**
306
     * Removes sensitive data from the user.
307
     */
308 24
    public function eraseCredentials()
309
    {
310
        // if you had a plainPassword property, you'd nullify it here
311
        // $this->plainPassword = null;
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
312 24
    }
313
314
    /**
315
     * @return bool
316
     */
317 24
    public function isAccountNonExpired()
318
    {
319 24
        return true;
320
    }
321
322
    /**
323
     * @return bool
324
     */
325 24
    public function isAccountNonLocked()
326
    {
327 24
        return true;
328
    }
329
330
    /**
331
     * @return bool
332
     */
333 24
    public function isCredentialsNonExpired()
334
    {
335 24
        return true;
336
    }
337
338
    /**
339
     * @return bool
340
     */
341 24
    public function isEnabled()
342
    {
343 24
        return $this->isActive;
344
    }
345
346
    /**
347
     * @return bool
348
     */
349 1
    public function getIsActive()
350
    {
351 1
        return $this->isActive;
352
    }
353
354
    /**
355
     * @param $active
356
     * @return mixed
357
     */
358 27
    public function setIsActive($active)
359
    {
360 27
        return $this->isActive = $active;
361
    }
362
363
    /**
364
     * @return string
365
     */
366
    public function getFacebookToken()
367
    {
368
        return $this->facebookToken;
369
    }
370
371
    /**
372
     * @param string $facebookToken
373
     */
374
    public function setFacebookToken($facebookToken)
375
    {
376
        $this->facebookToken = $facebookToken;
377
378
        return $this;
379
    }
380
381
    /**
382
     * @return string
383
     */
384
    public function getFacebookId()
385
    {
386
        return $this->facebookId;
387
    }
388
389
    /**
390
     * @param string $facebookId
391
     */
392
    public function setFacebookId($facebookId)
393
    {
394
        $this->facebookId = $facebookId;
395
396
        return $this;
397
    }
398
399
    /**
400
     * @return string
401
     */
402
    public function getGoogleToken()
403
    {
404
        return $this->googleToken;
405
    }
406
407
    /**
408
     * @param string $googleToken
409
     */
410
    public function setGoogleToken($googleToken)
411
    {
412
        $this->googleToken = $googleToken;
413
414
        return $this;
415
    }
416
417
    /**
418
     * @return string
419
     */
420
    public function getGoogleId()
421
    {
422
        return $this->googleId;
423
    }
424
425
    /**
426
     * @param string $googleId
427
     */
428
    public function setGoogleId($googleId)
429
    {
430
        $this->googleId = $googleId;
431
432
        return $this;
433
    }
434
435
436
    /**
437
     * Set type
438
     *
439
     * @param string $type
440
     * @return User
441
     */
442
    public function setType($type)
443
    {
444
        $this->type = $type;
445
446
        return $this;
447
    }
448
449
    /**
450
     * Get type
451
     *
452
     * @return string
453
     */
454
    public function getType()
455
    {
456
        return $this->type;
457
    }
458
459
    /**
460
     * @return mixed
461
     */
462
    public function getIsReg()
463
    {
464
        return $this->isReg;
465
    }
466
467
    /**
468
     * @param mixed $isReg
469
     */
470 27
    public function setIsReg($isReg)
471
    {
472 27
        $this->isReg = $isReg;
473
474 27
        return $this;
475
    }
476
477
    /**
478
     * @return mixed
479
     */
480
    public function getHash()
481
    {
482
        return $this->hash;
483
    }
484
485
    /**
486
     * @param mixed $hash
487
     */
488
    public function setHash($hash)
489
    {
490
        $this->hash = $hash;
491
492
        return $this;
493
    }
494
495 1
    public function getCountModules()
496
    {
497 1
        return count($this->modulesUser);
498
    }
499
500
}
501
502