Passed
Push — develop ( e1f02f...e3219b )
by Laurent
01:59
created

UpdateUser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 3
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\Infrastructure\Storage;
15
16
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...asswordEncoderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use User\Domain\Model\User as UserModel;
18
use User\Domain\Model\VO\Password;
19
use User\Infrastructure\Doctrine\Repository\UserRepository;
20
21
class UpdateUser
22
{
23
    private UserRepository $userRepository;
24
    private ReadUser $readUser;
25
    private UserPasswordEncoderInterface $passwordEncoder;
26
27
    public function __construct(
28
        UserRepository $userRepository,
29
        ReadUser $readUser,
30
        UserPasswordEncoderInterface $passwordEncoder
31
    ) {
32
        $this->userRepository = $userRepository;
33
        $this->readUser = $readUser;
34
        $this->passwordEncoder = $passwordEncoder;
35
    }
36
37
    public function update(UserModel $userModel): void
38
    {
39
        $userEntity = $this->readUser->findOneByUuid($userModel->uuid()->__toString());
40
41
        if ($this->passwordEncoder->isPasswordValid($userEntity, $userModel->password()->value())) {
42
            $encodedPassword = $this->passwordEncoder->encodePassword($userEntity, $userModel->password()->value());
43
            $userModel->changePassword(Password::fromString($encodedPassword));
44
        }
45
46
        $userEntity->update($userModel);
47
48
        $this->userRepository->flush();
49
    }
50
}
51