Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
33.33% |
5 / 15 |
|
36.36% |
4 / 11 |
CRAP | |
0.00% |
0 / 1 |
User | |
33.33% |
5 / 15 |
|
36.36% |
4 / 11 |
46.85 | |
0.00% |
0 / 1 |
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getEmail | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setEmail | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getUserIdentifier | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getUsername | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRoles | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setRoles | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getPassword | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setPassword | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getSalt | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
eraseCredentials | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace App\Entity; |
4 | |
5 | use App\Repository\UserRepository; |
6 | use Doctrine\ORM\Mapping as ORM; |
7 | use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; |
8 | use Symfony\Component\Security\Core\User\UserInterface; |
9 | use Symfony\Component\Validator\Constraints as Assert; |
10 | |
11 | /** |
12 | * @ORM\Entity(repositoryClass=UserRepository::class) |
13 | */ |
14 | class User implements UserInterface, PasswordAuthenticatedUserInterface |
15 | { |
16 | /** |
17 | * @ORM\Id |
18 | * @ORM\GeneratedValue |
19 | * @ORM\Column(type="integer") |
20 | */ |
21 | private $id; |
22 | |
23 | /** |
24 | * @ORM\Column(type="string", length=180, unique=true) |
25 | */ |
26 | private $email; |
27 | |
28 | /** |
29 | * @ORM\Column(type="json") |
30 | */ |
31 | private $roles = []; |
32 | |
33 | /** |
34 | * @var string The hashed password |
35 | * @ORM\Column(type="string") |
36 | * |
37 | */ |
38 | private $password; |
39 | |
40 | public function getId(): ?int |
41 | { |
42 | return $this->id; |
43 | } |
44 | |
45 | public function getEmail(): ?string |
46 | { |
47 | return $this->email; |
48 | } |
49 | |
50 | public function setEmail(string $email): self |
51 | { |
52 | $this->email = $email; |
53 | |
54 | return $this; |
55 | } |
56 | |
57 | /** |
58 | * A visual identifier that represents this user. |
59 | * |
60 | * @see UserInterface |
61 | */ |
62 | public function getUserIdentifier(): string |
63 | { |
64 | return (string) $this->email; |
65 | } |
66 | |
67 | /** |
68 | * @deprecated since Symfony 5.3, use getUserIdentifier instead |
69 | */ |
70 | public function getUsername(): string |
71 | { |
72 | return (string) $this->email; |
73 | } |
74 | |
75 | /** |
76 | * @see UserInterface |
77 | */ |
78 | public function getRoles(): array |
79 | { |
80 | $roles = $this->roles; |
81 | // guarantee every user at least has ROLE_USER |
82 | // $roles[] = 'ROLE_USER'; |
83 | |
84 | return array_unique($roles); |
85 | } |
86 | |
87 | public function setRoles(array $roles): self |
88 | { |
89 | $this->roles = $roles; |
90 | |
91 | return $this; |
92 | } |
93 | |
94 | /** |
95 | * @see PasswordAuthenticatedUserInterface |
96 | */ |
97 | public function getPassword(): string |
98 | { |
99 | return $this->password; |
100 | } |
101 | |
102 | public function setPassword(string $password): self |
103 | { |
104 | $this->password = $password; |
105 | |
106 | return $this; |
107 | } |
108 | |
109 | /** |
110 | * Returning a salt is only needed, if you are not using a modern |
111 | * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml. |
112 | * |
113 | * @see UserInterface |
114 | */ |
115 | public function getSalt(): ?string |
116 | { |
117 | return null; |
118 | } |
119 | |
120 | /** |
121 | * @see UserInterface |
122 | */ |
123 | public function eraseCredentials() |
124 | { |
125 | // If you store any temporary, sensitive data on the user, clear it here |
126 | // $this->plainPassword = null; |
127 | } |
128 | } |