• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemsdk / docker-symfony-api / #83

pending completion
#83

push

DKravtsov
Updated composer dependencies, refactoring.

45 of 45 new or added lines in 12 files covered. (100.0%)

1483 of 2844 relevant lines covered (52.14%)

22.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.44
/src/User/Domain/Entity/User.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\User\Domain\Entity;
6

7
use App\General\Domain\Doctrine\DBAL\Types\EnumLocaleType;
8
use App\General\Domain\Doctrine\DBAL\Types\Types as AppTypes;
9
use App\General\Domain\Entity\Interfaces\EntityInterface;
10
use App\General\Domain\Entity\Traits\Timestampable;
11
use App\General\Domain\Entity\Traits\Uuid;
12
use App\General\Domain\Enum\Language;
13
use App\Tool\Domain\Service\Interfaces\LocalizationServiceInterface;
14
use App\User\Domain\Entity\Interfaces\UserGroupAwareInterface;
15
use App\User\Domain\Entity\Interfaces\UserInterface;
16
use App\User\Domain\Entity\Traits\Blameable;
17
use App\User\Domain\Entity\Traits\UserRelations;
18
use Doctrine\Common\Collections\ArrayCollection;
19
use Doctrine\DBAL\Types\Types;
20
use Doctrine\ORM\Mapping as ORM;
21
use OpenApi\Annotations as OA;
22
use Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType;
23
use Ramsey\Uuid\UuidInterface;
24
use Symfony\Bridge\Doctrine\Validator\Constraints as AssertCollection;
25
use Symfony\Component\Serializer\Annotation\Groups;
26
use Symfony\Component\Validator\Constraints as Assert;
27
use Throwable;
28
use UnexpectedValueException;
29

30
use function in_array;
31

32
/**
33
 * Class User
34
 *
35
 * @package App\User
36
 */
37
#[ORM\Entity]
38
#[ORM\Table(name: 'user')]
39
#[ORM\UniqueConstraint(
40
    name: 'uq_username',
41
    columns: ['username'],
42
)]
43
#[ORM\UniqueConstraint(
44
    name: 'uq_email',
45
    columns: ['email'],
46
)]
47
#[ORM\ChangeTrackingPolicy('DEFERRED_EXPLICIT')]
48
#[AssertCollection\UniqueEntity('email')]
49
#[AssertCollection\UniqueEntity('username')]
50
class User implements EntityInterface, UserInterface, UserGroupAwareInterface
51
{
52
    use Blameable;
53
    use Timestampable;
54
    use UserRelations;
55
    use Uuid;
56

57
    public const SET_USER_PROFILE = 'set.UserProfile';
58
    public const SET_USER_BASIC = 'set.UserBasic';
59

60
    public const PASSWORD_MIN_LENGTH = 8;
61

62
    /**
63
     * @OA\Property(type="string", format="uuid")
64
     */
65
    #[ORM\Id]
66
    #[ORM\Column(
67
        name: 'id',
68
        type: UuidBinaryOrderedTimeType::NAME,
69
        unique: true,
70
        nullable: false,
71
    )]
72
    #[Groups([
73
        'User',
74
        'User.id',
75

76
        'LogLogin.user',
77
        'LogLoginFailure.user',
78
        'LogRequest.user',
79

80
        'UserGroup.users',
81

82
        self::SET_USER_PROFILE,
83
        self::SET_USER_BASIC,
84
    ])]
85
    private UuidInterface $id;
86

87
    #[ORM\Column(
88
        name: 'username',
89
        type: Types::STRING,
90
        length: 255,
91
        nullable: false,
92
    )]
93
    #[Groups([
94
        'User',
95
        'User.username',
96

97
        self::SET_USER_PROFILE,
98
        self::SET_USER_BASIC,
99
    ])]
100
    #[Assert\NotBlank]
101
    #[Assert\NotNull]
102
    #[Assert\Length(
103
        min: 2,
104
        max: 255,
105
    )]
106
    private string $username = '';
107

108
    #[ORM\Column(
109
        name: 'first_name',
110
        type: Types::STRING,
111
        length: 255,
112
        nullable: false,
113
    )]
114
    #[Groups([
115
        'User',
116
        'User.firstName',
117

118
        self::SET_USER_PROFILE,
119
        self::SET_USER_BASIC,
120
    ])]
121
    #[Assert\NotBlank]
122
    #[Assert\NotNull]
123
    #[Assert\Length(
124
        min: 2,
125
        max: 255,
126
    )]
127
    private string $firstName = '';
128

129
    #[ORM\Column(
130
        name: 'last_name',
131
        type: Types::STRING,
132
        length: 255,
133
        nullable: false,
134
    )]
135
    #[Groups([
136
        'User',
137
        'User.lastName',
138

139
        self::SET_USER_PROFILE,
140
        self::SET_USER_BASIC,
141
    ])]
142
    #[Assert\NotBlank]
143
    #[Assert\NotNull]
144
    #[Assert\Length(
145
        min: 2,
146
        max: 255,
147
    )]
148
    private string $lastName = '';
149

150
    #[ORM\Column(
151
        name: 'email',
152
        type: Types::STRING,
153
        length: 255,
154
        nullable: false,
155
    )]
156
    #[Groups([
157
        'User',
158
        'User.email',
159

160
        self::SET_USER_PROFILE,
161
        self::SET_USER_BASIC,
162
    ])]
163
    #[Assert\NotBlank]
164
    #[Assert\NotNull]
165
    #[Assert\Email]
166
    private string $email = '';
167

168
    #[ORM\Column(
169
        name: 'language',
170
        type: AppTypes::ENUM_LANGUAGE,
171
        nullable: false,
172
        options: [
173
            'comment' => 'User language for translations',
174
        ],
175
    )]
176
    #[Groups([
177
        'User',
178
        'User.language',
179

180
        self::SET_USER_PROFILE,
181
        self::SET_USER_BASIC,
182
    ])]
183
    #[Assert\NotBlank]
184
    #[Assert\NotNull]
185
    private Language $language;
186

187
    #[ORM\Column(
188
        name: 'locale',
189
        type: AppTypes::ENUM_LOCALE,
190
        nullable: false,
191
        options: [
192
            'comment' => 'User locale for number, time, date, etc. formatting.',
193
        ],
194
    )]
195
    #[Groups([
196
        'User',
197
        'User.locale',
198

199
        self::SET_USER_PROFILE,
200
        self::SET_USER_BASIC,
201
    ])]
202
    #[Assert\NotBlank]
203
    #[Assert\NotNull]
204
    private string $locale = LocalizationServiceInterface::DEFAULT_LOCALE;
205

206
    #[ORM\Column(
207
        name: 'timezone',
208
        type: Types::STRING,
209
        length: 255,
210
        nullable: false,
211
        options: [
212
            'comment' => 'User timezone which should be used to display time, date, etc.',
213
            'default' => LocalizationServiceInterface::DEFAULT_TIMEZONE,
214
        ],
215
    )]
216
    #[Groups([
217
        'User',
218
        'User.timezone',
219

220
        self::SET_USER_PROFILE,
221
        self::SET_USER_BASIC,
222
    ])]
223
    #[Assert\NotBlank]
224
    #[Assert\NotNull]
225
    private string $timezone = LocalizationServiceInterface::DEFAULT_TIMEZONE;
226

227
    #[ORM\Column(
228
        name: 'password',
229
        type: Types::STRING,
230
        length: 255,
231
        nullable: false,
232
        options: [
233
            'comment' => 'Hashed password',
234
        ],
235
    )]
236
    private string $password = '';
237

238
    /**
239
     * Plain password. Used for model validation. Must not be persisted.
240
     *
241
     * @see UserEntityEventListener
242
     */
243
    private string $plainPassword = '';
244

245
    /**
246
     * Constructor
247
     *
248
     * @throws Throwable
249
     */
250
    public function __construct()
251
    {
252
        $this->id = $this->createUuid();
2✔
253
        $this->language = Language::getDefault();
2✔
254
        $this->userGroups = new ArrayCollection();
2✔
255
        $this->logsRequest = new ArrayCollection();
2✔
256
        $this->logsLogin = new ArrayCollection();
2✔
257
        $this->logsLoginFailure = new ArrayCollection();
2✔
258
    }
259

260
    public function getId(): string
261
    {
262
        return $this->id->toString();
129✔
263
    }
264

265
    public function getUsername(): string
266
    {
267
        return $this->username;
33✔
268
    }
269

270
    public function setUsername(string $username): self
271
    {
272
        $this->username = $username;
3✔
273

274
        return $this;
3✔
275
    }
276

277
    public function getFirstName(): string
278
    {
279
        return $this->firstName;
14✔
280
    }
281

282
    public function setFirstName(string $firstName): self
283
    {
284
        $this->firstName = $firstName;
3✔
285

286
        return $this;
3✔
287
    }
288

289
    public function getLastName(): string
290
    {
291
        return $this->lastName;
14✔
292
    }
293

294
    public function setLastName(string $lastName): self
295
    {
296
        $this->lastName = $lastName;
3✔
297

298
        return $this;
3✔
299
    }
300

301
    public function getEmail(): string
302
    {
303
        return $this->email;
14✔
304
    }
305

306
    public function setEmail(string $email): self
307
    {
308
        $this->email = $email;
3✔
309

310
        return $this;
3✔
311
    }
312

313
    public function getLanguage(): Language
314
    {
315
        return $this->language;
127✔
316
    }
317

318
    public function setLanguage(Language $language): self
319
    {
320
        $this->language = $language;
2✔
321

322
        return $this;
2✔
323
    }
324

325
    public function getLocale(): string
326
    {
327
        return $this->locale;
127✔
328
    }
329

330
    public function setLocale(string $locale): self
331
    {
332
        if (in_array($locale, EnumLocaleType::getValues(), true) !== true) {
2✔
333
            throw new UnexpectedValueException(sprintf("Invalid locale value: '%s'", $locale));
×
334
        }
335

336
        $this->locale = $locale;
2✔
337

338
        return $this;
2✔
339
    }
340

341
    public function getTimezone(): string
342
    {
343
        return $this->timezone;
127✔
344
    }
345

346
    public function setTimezone(string $timezone): self
347
    {
348
        $this->timezone = $timezone;
2✔
349

350
        return $this;
2✔
351
    }
352

353
    public function getPassword(): string
354
    {
355
        return $this->password;
127✔
356
    }
357

358
    public function setPassword(callable $encoder, string $plainPassword): self
359
    {
360
        $this->password = (string)$encoder($plainPassword);
4✔
361

362
        return $this;
4✔
363
    }
364

365
    public function getPlainPassword(): string
366
    {
367
        return $this->plainPassword;
10✔
368
    }
369

370
    public function setPlainPassword(string $plainPassword): self
371
    {
372
        if ($plainPassword !== '') {
4✔
373
            $this->plainPassword = $plainPassword;
4✔
374

375
            // Change some mapped values so preUpdate will get called - just blank it out
376
            $this->password = '';
4✔
377
        }
378

379
        return $this;
4✔
380
    }
381

382
    /**
383
     * Removes sensitive data from the user.
384
     *
385
     * This is important if, at any given point, sensitive information like
386
     * the plain-text password is stored on this object.
387
     */
388
    public function eraseCredentials(): void
389
    {
390
        $this->plainPassword = '';
4✔
391
    }
392
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc