Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
57.14% |
16 / 28 |
|
68.75% |
11 / 16 |
CRAP | |
0.00% |
0 / 1 |
| User | |
57.14% |
16 / 28 |
|
68.75% |
11 / 16 |
47.42 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getEmail | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setEmail | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getUserIdentifier | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUsername | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRoles | |
100.00% |
3 / 3 |
|
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 | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getSalt | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| eraseCredentials | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setUsername | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getTasks | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| addTask | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| removeTask | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Entity; |
| 4 | |
| 5 | use App\Repository\UserRepository; |
| 6 | use Doctrine\Common\Collections\ArrayCollection; |
| 7 | use Doctrine\Common\Collections\Collection; |
| 8 | use Doctrine\ORM\Mapping as ORM; |
| 9 | use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; |
| 10 | use Symfony\Component\Security\Core\User\UserInterface; |
| 11 | |
| 12 | #[ORM\Entity(repositoryClass:UserRepository::class)] |
| 13 | class User implements UserInterface, PasswordAuthenticatedUserInterface |
| 14 | { |
| 15 | #[ORM\Id] |
| 16 | #[ORM\GeneratedValue] |
| 17 | #[ORM\Column(type:"integer")] |
| 18 | private ?int $id = null; |
| 19 | |
| 20 | #[ORM\Column(type:"string", length:180, unique:true)] |
| 21 | private string $email; |
| 22 | |
| 23 | #[ORM\Column(type:"json")] |
| 24 | private array $roles = []; |
| 25 | |
| 26 | #[ORM\Column(type:"string")] |
| 27 | /** |
| 28 | * @var string The hashed password |
| 29 | */ |
| 30 | private string $password; |
| 31 | |
| 32 | #[ORM\Column(type:"string", length:255)] |
| 33 | private string $username; |
| 34 | |
| 35 | #[ORM\OneToMany(mappedBy:"user", targetEntity:Task::class)] |
| 36 | private $tasks; |
| 37 | |
| 38 | public function __construct() |
| 39 | { |
| 40 | $this->tasks = new ArrayCollection(); |
| 41 | } |
| 42 | |
| 43 | public function getId(): ?int |
| 44 | { |
| 45 | return $this->id; |
| 46 | } |
| 47 | |
| 48 | public function getEmail(): ?string |
| 49 | { |
| 50 | return $this->email; |
| 51 | } |
| 52 | |
| 53 | public function setEmail(string $email): self |
| 54 | { |
| 55 | $this->email = $email; |
| 56 | |
| 57 | return $this; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * A visual identifier that represents this user. |
| 62 | * |
| 63 | * @see UserInterface |
| 64 | */ |
| 65 | public function getUserIdentifier(): string |
| 66 | { |
| 67 | return (string) $this->username; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @deprecated since Symfony 5.3, use getUserIdentifier instead |
| 72 | */ |
| 73 | public function getUsername(): string |
| 74 | { |
| 75 | return (string) $this->username; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @see UserInterface |
| 80 | */ |
| 81 | public function getRoles(): array |
| 82 | { |
| 83 | $roles = $this->roles; |
| 84 | // guarantee every user at least has ROLE_USER |
| 85 | $roles[] = 'ROLE_USER'; |
| 86 | |
| 87 | return array_unique($roles); |
| 88 | } |
| 89 | |
| 90 | public function setRoles(array $roles): self |
| 91 | { |
| 92 | $this->roles = $roles; |
| 93 | |
| 94 | return $this; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @see PasswordAuthenticatedUserInterface |
| 99 | */ |
| 100 | public function getPassword(): string |
| 101 | { |
| 102 | return $this->password; |
| 103 | } |
| 104 | |
| 105 | public function setPassword(string $password): self |
| 106 | { |
| 107 | $this->password = $password; |
| 108 | |
| 109 | return $this; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Returning a salt is only needed, if you are not using a modern |
| 114 | * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml. |
| 115 | * |
| 116 | * @see UserInterface |
| 117 | */ |
| 118 | public function getSalt(): ?string |
| 119 | { |
| 120 | return null; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @see UserInterface |
| 125 | */ |
| 126 | public function eraseCredentials() |
| 127 | { |
| 128 | // If you store any temporary, sensitive data on the user, clear it here |
| 129 | // $this->plainPassword = null; |
| 130 | } |
| 131 | |
| 132 | public function setUsername(string $username): self |
| 133 | { |
| 134 | $this->username = $username; |
| 135 | |
| 136 | return $this; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * @return Collection<int, Task> |
| 141 | */ |
| 142 | public function getTasks(): Collection |
| 143 | { |
| 144 | return $this->tasks; |
| 145 | } |
| 146 | |
| 147 | public function addTask(Task $task): self |
| 148 | { |
| 149 | if (!$this->tasks->contains($task)) { |
| 150 | $this->tasks[] = $task; |
| 151 | $task->setAuthor($this); |
| 152 | } |
| 153 | |
| 154 | return $this; |
| 155 | } |
| 156 | |
| 157 | public function removeTask(Task $task): self |
| 158 | { |
| 159 | if ($this->tasks->removeElement($task)) { |
| 160 | if ($task->getAuthor() === $this) { |
| 161 | $task->setAuthor(null); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | return $this; |
| 166 | } |
| 167 | } |