Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
15 / 15
CRAP
100.00% covered (success)
100.00%
1 / 1
User
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
15 / 15
18
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEmail
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setEmail
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getUserIdentifier
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRoles
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 setRoles
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getPassword
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setPassword
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 eraseCredentials
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUsername
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setUsername
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getTasks
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addTask
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 removeTask
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace App\Entity;
4
5use Doctrine\ORM\Mapping as ORM;
6use App\Repository\UserRepository;
7use Doctrine\Common\Collections\Collection;
8use Doctrine\Common\Collections\ArrayCollection;
9use Symfony\Component\Validator\Constraints as Assert;
10use Symfony\Component\Security\Core\User\UserInterface;
11use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
12use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
13
14#[ORM\Entity(repositoryClass: UserRepository::class)]
15#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
16#[UniqueEntity(fields: ['username'], message: 'There is already an account with this username')]
17class User implements UserInterface, PasswordAuthenticatedUserInterface
18{
19    #[ORM\Id]
20    #[ORM\GeneratedValue]
21    #[ORM\Column]
22    private ?int $id = null;
23
24    #[ORM\Column(length: 180, unique: true)]
25    #[Assert\NotBlank(message: 'Vous devez saisir une adresse email')]
26    #[Assert\Email(message: 'Vous devez saisir une adresse email valide')]
27    private ?string $email = null;
28
29    #[ORM\Column]
30    /**
31     * @var array<string>
32     * @phpstan-ignore-next-line
33     */
34    private array $roles = [];
35
36    /**
37     * @var string The hashed password
38     */
39    #[ORM\Column(length: 64)]
40    #[Assert\Length(min: 8, minMessage: 'Votre mot de passe doit contenir au moins 8 caractères')]
41    // phpcs:ignore
42    #[Assert\Regex(pattern: '/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/', message: 'Votre mot de passe doit contenir au moins une lettre majuscule, une lettre minuscule et un chiffre')]
43    private ?string $password = null;
44
45    #[ORM\Column(length: 25, unique: true)]
46    #[Assert\NotBlank(message: 'Vous devez saisir un nom d\'utilisateur')]
47    #[Assert\Length(min: 3, minMessage: 'Votre mot de passe doit contenir au moins 3 caractères')]
48    private ?string $username = null;
49
50    #[ORM\OneToMany(mappedBy: 'author', targetEntity: Task::class)]
51    private Collection $tasks;
52
53    public function __construct()
54    {
55        $this->tasks = new ArrayCollection();
56    }
57
58    public function getId(): ?int
59    {
60        return $this->id;
61    }
62
63    public function getEmail(): ?string
64    {
65        return $this->email;
66    }
67
68    public function setEmail(string $email): self
69    {
70        $this->email = $email;
71
72        return $this;
73    }
74
75    /**
76     * A visual identifier that represents this user.
77     *
78     * @see UserInterface
79     */
80    public function getUserIdentifier(): string
81    {
82        return (string) $this->email;
83    }
84
85    /**
86     * @see UserInterface
87     * @return array<string>
88     */
89    public function getRoles(): array
90    {
91        $roles = $this->roles;
92        // guarantee every user at least has ROLE_USER
93        $roles[] = 'ROLE_USER';
94
95        return array_unique($roles);
96    }
97
98    /**
99     * @param array<string> $roles
100     * @return self
101     */
102    public function setRoles(array $roles): self
103    {
104        $this->roles = $roles;
105
106        return $this;
107    }
108
109    /**
110     * @see PasswordAuthenticatedUserInterface
111     */
112    public function getPassword(): string
113    {
114        return $this->password;
115    }
116
117    public function setPassword(string $password): self
118    {
119        $this->password = $password;
120
121        return $this;
122    }
123
124    /**
125     * @see UserInterface
126     */
127    public function eraseCredentials(): void
128    {
129        // If you store any temporary, sensitive data on the user, clear it here
130        // $this->plainPassword = null;
131    }
132
133    public function getUsername(): ?string
134    {
135        return $this->username;
136    }
137
138    public function setUsername(string $username): self
139    {
140        $this->username = $username;
141
142        return $this;
143    }
144
145    /**
146     * @return Collection<int, Task>
147     */
148    public function getTasks(): Collection
149    {
150        return $this->tasks;
151    }
152
153    public function addTask(Task $task): self
154    {
155        if (!$this->tasks->contains($task)) {
156            $this->tasks->add($task);
157            $task->setAuthor($this);
158        }
159
160        return $this;
161    }
162
163    public function removeTask(Task $task): self
164    {
165        if ($this->tasks->removeElement($task)) {
166            // set the owning side to null (unless already changed)
167            if ($task->getAuthor() === $this) {
168                $task->setAuthor(null);
169            }
170        }
171
172        return $this;
173    }
174}