1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the G.L.S.R. Apps package. |
7
|
|
|
* |
8
|
|
|
* (c) Dev-Int Création <[email protected]>. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace User\Application\Handler; |
15
|
|
|
|
16
|
|
|
use Core\Domain\Protocol\Common\Command\CommandHandlerInterface; |
17
|
|
|
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; |
|
|
|
|
18
|
|
|
use User\Application\Command\CreateUser as CreateUserCommand; |
19
|
|
|
use User\Application\Factory\CreateUser as CreateUserFactory; |
20
|
|
|
use User\Domain\Exception\UserAlreadyExistException; |
21
|
|
|
use User\Domain\Model\VO\Password; |
22
|
|
|
use User\Infrastructure\Doctrine\Entity\User; |
23
|
|
|
use User\Infrastructure\Storage\ReadUser; |
24
|
|
|
use User\Infrastructure\Storage\SaveUser; |
25
|
|
|
|
26
|
|
|
final class CreateUser implements CommandHandlerInterface |
27
|
|
|
{ |
28
|
|
|
private UserPasswordEncoderInterface $passwordEncoder; |
29
|
|
|
private ReadUser $readUser; |
30
|
|
|
private SaveUser $saveUser; |
31
|
|
|
private CreateUserFactory $createUserFactory; |
32
|
|
|
|
33
|
|
|
public function __construct( |
34
|
|
|
ReadUser $readUser, |
35
|
|
|
SaveUser $saveUser, |
36
|
|
|
CreateUserFactory $createUserFactory, |
37
|
|
|
UserPasswordEncoderInterface $passwordEncoder |
38
|
|
|
) { |
39
|
|
|
$this->passwordEncoder = $passwordEncoder; |
40
|
|
|
$this->readUser = $readUser; |
41
|
|
|
$this->saveUser = $saveUser; |
42
|
|
|
$this->createUserFactory = $createUserFactory; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function __invoke(CreateUserCommand $command): void |
46
|
|
|
{ |
47
|
|
|
if ($this->readUser->existsWithUsername($command->username()) |
48
|
|
|
|| $this->readUser->existsWithEmail($command->email()) |
49
|
|
|
) { |
50
|
|
|
throw new UserAlreadyExistException(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$user = $this->createUserFactory->createUser($command); |
54
|
|
|
|
55
|
|
|
$userSymfony = User::fromModel($user); |
56
|
|
|
$passwordEncoded = $this->passwordEncoder->encodePassword( |
57
|
|
|
$userSymfony, |
58
|
|
|
$command->password() |
59
|
|
|
); |
60
|
|
|
$user->changePassword(Password::fromString($passwordEncoded)); |
61
|
|
|
|
62
|
|
|
$this->saveUser->save($user); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths