Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
36 / 36
100.00% covered (success)
100.00%
25 / 25
CRAP
100.00% covered (success)
100.00%
1 / 1
User
100.00% covered (success)
100.00%
36 / 36
100.00% covered (success)
100.00%
25 / 25
27
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
 prePersist
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 preUpdate
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
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDescription
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDescription
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMedias
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setMedias
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isSuperAdmin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setSuperAdmin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isAdmin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAdmin
100.00% covered (success)
100.00%
1 / 1
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
 getCreatedAt
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCreatedAt
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getUpdatedAt
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setUpdatedAt
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getRoles
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 getUserIdentifier
100.00% covered (success)
100.00%
1 / 1
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
1<?php
2
3namespace App\Entity;
4
5use App\Repository\UserRepository;
6use Doctrine\Common\Collections\ArrayCollection;
7use Doctrine\Common\Collections\Collection;
8use Doctrine\DBAL\Types\Types;
9use Doctrine\ORM\Mapping as ORM;
10use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
11use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
12use Symfony\Component\Security\Core\User\UserInterface;
13use Symfony\Component\Validator\Constraints as Assert;
14
15#[ORM\Entity(repositoryClass: UserRepository::class)]
16#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', columns: ['email'])]
17#[UniqueEntity(fields: ['email'], message: 'Cet email est déjà utilisé.')]
18#[ORM\Table(name: '`user`')]
19#[ORM\HasLifecycleCallbacks]
20class User implements UserInterface, PasswordAuthenticatedUserInterface
21{
22    #[ORM\Id]
23    #[ORM\GeneratedValue]
24    #[ORM\Column]
25    private ?int $id = null;
26
27    #[ORM\Column]
28    private bool $super_admin = false;
29
30    #[ORM\Column(options: ['default' => true])]
31    private bool $admin = true;
32
33    #[ORM\Column]
34    #[Assert\NotBlank(message: 'Le nom ne peut pas être vide.')]
35    #[Assert\Length(
36        max: 255,
37        maxMessage: 'Le nom ne peut pas dépasser {{ limit }} caractères.'
38    )]
39    private ?string $name;
40
41    #[ORM\Column(type: 'text', nullable: true)]
42    #[Assert\Length(
43        max: 1000,
44        maxMessage: 'La description ne peut pas dépasser {{ limit }} caractères.'
45    )]
46    private ?string $description;
47
48    #[ORM\Column(length: 180)]
49    #[Assert\NotBlank(message: 'L\'email est obligatoire.')]
50    #[Assert\Email(message: 'L\'email "{{ value }}" n\'est pas valide.')]
51    #[Assert\Length(
52        max: 180,
53        maxMessage: 'L\'email ne peut pas dépasser {{ limit }} caractères.'
54    )]
55    private ?string $email = null;
56
57    #[ORM\Column]
58    private ?string $password = null;
59
60    #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
61    private ?\DateTimeImmutable $createdAt = null;
62
63    #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
64    private ?\DateTimeImmutable $updatedAt = null;
65
66    /**
67     * @var Collection<int, Media>
68     */
69    #[ORM\OneToMany(targetEntity: Media::class, mappedBy: 'user', orphanRemoval: true, cascade: ['remove'])]
70    private Collection $medias;
71
72    public function __construct()
73    {
74        $this->medias = new ArrayCollection();
75    }
76
77    #[ORM\PrePersist]
78    public function prePersist(): void
79    {
80        $now = new \DateTimeImmutable('now', new \DateTimeZone('Europe/Paris'));
81        $this->createdAt = $now;
82        $this->updatedAt = $now;
83    }
84
85    #[ORM\PreUpdate]
86    public function preUpdate(): void
87    {
88        $this->updatedAt = new \DateTimeImmutable('now', new \DateTimeZone('Europe/Paris'));
89    }
90
91    public function getId(): ?int
92    {
93        return $this->id;
94    }
95
96    public function getEmail(): ?string
97    {
98        return $this->email;
99    }
100
101    public function setEmail(string $email): static
102    {
103        $this->email = $email;
104
105        return $this;
106    }
107
108    public function getName(): ?string
109    {
110        return $this->name;
111    }
112
113    public function setName(?string $name): void
114    {
115        $this->name = $name;
116    }
117
118    public function getDescription(): ?string
119    {
120        return $this->description;
121    }
122
123    public function setDescription(?string $description): void
124    {
125        $this->description = $description;
126    }
127
128    /**
129     * @return Collection<int, Media>
130     */
131    public function getMedias(): Collection
132    {
133        return $this->medias;
134    }
135
136    /**
137     * @param Collection<int, Media> $medias
138     */
139    public function setMedias(Collection $medias): void
140    {
141        $this->medias = $medias;
142    }
143
144    public function isSuperAdmin(): bool
145    {
146        return $this->super_admin;
147    }
148
149    public function setSuperAdmin(bool $super_admin): void
150    {
151        $this->super_admin = $super_admin;
152    }
153
154    public function isAdmin(): bool
155    {
156        return $this->admin;
157    }
158
159    public function setAdmin(bool $admin): void
160    {
161        $this->admin = $admin;
162    }
163
164    public function getPassword(): ?string
165    {
166        return $this->password;
167    }
168
169    public function setPassword(string $password): static
170    {
171        $this->password = $password;
172
173        return $this;
174    }
175
176    public function getCreatedAt(): ?\DateTimeImmutable
177    {
178        return $this->createdAt;
179    }
180
181    public function setCreatedAt(\DateTimeImmutable $createdAt): static
182    {
183        $this->createdAt = $createdAt;
184
185        return $this;
186    }
187
188    public function getUpdatedAt(): ?\DateTimeImmutable
189    {
190        return $this->updatedAt;
191    }
192
193    public function setUpdatedAt(\DateTimeImmutable $updatedAt): static
194    {
195        $this->updatedAt = $updatedAt;
196
197        return $this;
198    }
199
200    public function getRoles(): array
201    {
202        $roles = ['ROLE_USER'];
203        if ($this->isSuperAdmin()) {
204            $roles[] = 'ROLE_SUPER_ADMIN';
205        }
206        if ($this->isAdmin()) {
207            $roles[] = 'ROLE_ADMIN';
208        }
209
210        return array_unique($roles);
211    }
212
213    public function getUserIdentifier(): string
214    {
215        return (string) $this->email;
216    }
217
218    public function eraseCredentials(): void {}
219}