Completed
Push — master ( b2b032...858bee )
by Pavel
09:16 queued 06:10
created

User::removeChosenModule()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 5
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
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
    /**
95
     * @ORM\Column(name="is_locked", type="boolean")
96
     */
97
    protected $isLocked;
98
99
    /**
100
     * @ORM\Column(name="hash", type="string", nullable=true)
101
     */
102
    protected $hash;
103
104
    /**
105
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\ModuleUser", mappedBy="user", cascade={"remove"})
106
     */
107
    private $modulesUser;
108
109
    /**
110
     * @ORM\Column(name="chosen_module", type="array")
111
     */
112
    private $chosenModule;
113
114
    public function jsonSerialize()
115
    {
116
        return [
117
            'id' => $this->getId(),
118
            'firstName' => $this->getFirstName(),
119
            'lastName' => $this->getLastName(),
120
            'email' => $this->getEmail()
121
        ];
122
    }
123
124 27
    public function __construct()
125
    {
126 27
        $this->isActive = false;
127 27
        $this->isLocked = false;
128 27
        $this->modulesUser = new ArrayCollection();
129 27
        $this->role = self::ROLE_USER;
130 27
        $this->chosenModule = [];
131 27
    }
132
133
    /**
134
     * @return mixed
135
     */
136
    public function getModulesUser()
137
    {
138
        return $this->modulesUser;
139
    }
140
141
    /**
142
     * @param ModuleUser $moduleUser
143
     * @return $this
144
     */
145
    public function addModuleUser(ModuleUser $moduleUser)
146
    {
147
        $this->modulesUser->add($moduleUser);
148
149
        return $this;
150
    }
151
152
    /**
153
     * @param ModuleUser $moduleUser
154
     */
155
    public function removeModuleUser(ModuleUser $moduleUser)
156
    {
157
        $this->modulesUser->removeElement($moduleUser);
158
    }
159
160
    /**
161
     * @return mixed
162
     */
163 6
    public function getId()
164
    {
165 6
        return $this->id;
166
    }
167
168
    /**
169
     * {@inheritdoc}
170
     */
171
    public function getUsername()
172
    {
173
        return $this->getEmail();
174
    }
175
176
    /**
177
     * @return mixed
178
     */
179 4
    public function getEmail()
180
    {
181 4
        return $this->email;
182
    }
183
184
    /**
185
     * @param $email
186
     */
187 27
    public function setEmail($email)
188
    {
189 27
        $this->email = $email;
190
191 27
        return $this;
192
    }
193
194
    /**
195
     * @return mixed
196
     */
197 5
    public function getFirstName()
198
    {
199 5
        return $this->firstName;
200
    }
201
202
    /**
203
     * @param mixed $firstName
204
     */
205 27
    public function setFirstName($firstName)
206
    {
207 27
        $this->firstName = $firstName;
208
209 27
        return $this;
210
    }
211
212
    /**
213
     * @return mixed
214
     */
215 5
    public function getLastName()
216
    {
217 5
        return $this->lastName;
218
    }
219
220
    /**
221
     * @param mixed $lastName
222
     */
223 27
    public function setLastName($lastName)
224
    {
225 27
        $this->lastName = $lastName;
226
227 27
        return $this;
228
    }
229
230
    /**
231
     * {@inheritdoc}
232
     */
233 24
    public function getPassword()
234
    {
235 24
        return $this->password;
236
    }
237
238
    /**
239
     * @param $password
240
     */
241 27
    public function setPassword($password)
242
    {
243 27
        $this->password = $password;
244 27
    }
245
246
    /**
247
     * @param $role
248
     * @return $this
249
     */
250 27
    public function setRole($role)
251
    {
252 27
        $this->role = $role;
253
254 27
        return $this;
255
    }
256
257
    /**
258
     * @return mixed
259
     */
260
    public function getRole()
261
    {
262
        return $this->role;
263
    }
264
265
    /**
266
     * Returns the roles or permissions granted to the user for security.
267
     */
268 24
    public function getRoles()
269
    {
270 24
        return [$this->role];
271
272
    }
273
274
    /**
275
     * @return mixed
276
     */
277 1
    public function getPlainPassword()
278
    {
279 1
        return $this->plainPassword;
280
    }
281
282
    /**
283
     * @param $password
284
     */
285
    public function setPlainPassword($password)
286
    {
287
        $this->plainPassword = $password;
288
    }
289
290
    /**
291
     * Returns the salt that was originally used to encode the password.
292
     */
293 27
    public function getSalt()
294
    {
295
        // See "Do you need to use a Salt?" at http://symfony.com/doc/current/cookbook/security/entity_provider.html
296
        // we're using bcrypt in security.yml to encode the password, so
297
        // the salt value is built-in and you don't have to generate one
298
299 27
        return;
300
    }
301
302
    /**
303
     * Removes sensitive data from the user.
304
     */
305 24
    public function eraseCredentials()
306
    {
307
        // if you had a plainPassword property, you'd nullify it here
308
        // $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...
309 24
    }
310
311
    /**
312
     * @return bool
313
     */
314 24
    public function isAccountNonExpired()
315
    {
316 24
        return true;
317
    }
318
319
    /**
320
     * @return bool
321
     */
322 24
    public function isAccountNonLocked()
323
    {
324 24
        return $this->isLocked ? false : true ;
325
    }
326
327
    /**
328
     * @return bool
329
     */
330 24
    public function isCredentialsNonExpired()
331
    {
332 24
        return true;
333
    }
334
335
    /**
336
     * @return bool
337
     */
338 24
    public function isEnabled()
339
    {
340 24
        return $this->isActive;
341
    }
342
343
    /**
344
     * @return bool
345
     */
346
    public function getIsActive()
347
    {
348
        return $this->isActive;
349
    }
350
351
    /**
352
     * @param $active
353
     * @return mixed
354
     */
355 27
    public function setIsActive($active)
356
    {
357 27
        return $this->isActive = $active;
358
    }
359
360
    /**
361
     * @return bool
362
     */
363 2
    public function getIsLocked()
364
    {
365 2
        return $this->isLocked;
366
    }
367
368
    /**
369
     * @param $isLocked
370
     * @return mixed
371
     */
372
    public function setIsLocked($isLocked)
373
    {
374
        return $this->isLocked = $isLocked;
375
    }
376
377
    /**
378
     * @return string
379
     */
380
    public function getFacebookToken()
381
    {
382
        return $this->facebookToken;
383
    }
384
385
    /**
386
     * @param string $facebookToken
387
     * @return $this
388
     */
389
    public function setFacebookToken($facebookToken)
390
    {
391
        $this->facebookToken = $facebookToken;
392
393
        return $this;
394
    }
395
396
    /**
397
     * @return string
398
     */
399
    public function getFacebookId()
400
    {
401
        return $this->facebookId;
402
    }
403
404
    /**
405
     * @param string $facebookId
406
     * @return $this
407
     */
408
    public function setFacebookId($facebookId)
409
    {
410
        $this->facebookId = $facebookId;
411
412
        return $this;
413
    }
414
415
    /**
416
     * @return string
417
     */
418
    public function getGoogleToken()
419
    {
420
        return $this->googleToken;
421
    }
422
423
    /**
424
     * @param string $googleToken
425
     * @return $this
426
     */
427
    public function setGoogleToken($googleToken)
428
    {
429
        $this->googleToken = $googleToken;
430
431
        return $this;
432
    }
433
434
    /**
435
     * @return string
436
     */
437
    public function getGoogleId()
438
    {
439
        return $this->googleId;
440
    }
441
442
    /**
443
     * @param string $googleId
444
     * @return $this
445
     */
446
    public function setGoogleId($googleId)
447
    {
448
        $this->googleId = $googleId;
449
450
        return $this;
451
    }
452
453
    /**
454
     * @return mixed
455
     */
456
    public function getHash()
457
    {
458
        return $this->hash;
459
    }
460
461
    /**
462
     * @param mixed $hash
463
     * @return $this
464
     */
465
    public function setHash($hash)
466
    {
467
        $this->hash = $hash;
468
469
        return $this;
470
    }
471
472
    /**
473
     * @return mixed
474
     */
475
    public function getChosenModule()
476
    {
477
        return $this->chosenModule;
478
    }
479
480
    /**
481
     * @param mixed $chosenModule
482
     * @return $this
483
     */
484
    public function setChosenModule($chosenModule)
485
    {
486
        $this->chosenModule = $chosenModule;
487
488
        return $this;
489
    }
490
491
492
    public function removeChosenModule($chosenModule)
493
    {
494
        if(($key = array_search($chosenModule, $this->chosenModule)) !== false) {
495
            unset($this->chosenModule[$key]);
496
        }
497
498
        return $this;
499
    }
500
501 1
    public function getCountModules()
502
    {
503 1
        return count($this->modulesUser);
504
    }
505
506
}
507
508