Code Duplication    Length = 46-46 lines in 2 locations

src/BenGorUser/User/Application/Command/ChangePassword/ByRequestRememberPasswordChangeUserPasswordHandler.php 1 location

@@ 27-72 (lines=46) @@
24
 * @author Beñat Espiña <[email protected]>
25
 * @author Gorka Laucirica <[email protected]>
26
 */
27
class ByRequestRememberPasswordChangeUserPasswordHandler
28
{
29
    /**
30
     * The user password encoder.
31
     *
32
     * @var UserPasswordEncoder
33
     */
34
    private $encoder;
35
36
    /**
37
     * The user repository.
38
     *
39
     * @var UserRepository
40
     */
41
    private $repository;
42
43
    /**
44
     * Constructor.
45
     *
46
     * @param UserRepository      $aRepository The user repository
47
     * @param UserPasswordEncoder $anEncoder   The password encoder
48
     */
49
    public function __construct(UserRepository $aRepository, UserPasswordEncoder $anEncoder)
50
    {
51
        $this->repository = $aRepository;
52
        $this->encoder = $anEncoder;
53
    }
54
55
    /**
56
     * Handles the given command.
57
     *
58
     * @param ByRequestRememberPasswordChangeUserPasswordCommand $aCommand The command
59
     *
60
     * @throws UserDoesNotExistException when the user does not exist
61
     */
62
    public function __invoke(ByRequestRememberPasswordChangeUserPasswordCommand $aCommand)
63
    {
64
        $user = $this->repository->userOfRememberPasswordToken(new UserToken($aCommand->rememberPasswordToken()));
65
        if (null === $user) {
66
            throw new UserDoesNotExistException();
67
        }
68
        $user->changePassword(UserPassword::fromPlain($aCommand->newPlainPassword(), $this->encoder));
69
70
        $this->repository->persist($user);
71
    }
72
}
73

src/BenGorUser/User/Application/Command/ChangePassword/WithoutOldPasswordChangeUserPasswordHandler.php 1 location

@@ 27-72 (lines=46) @@
24
 * @author Beñat Espiña <[email protected]>
25
 * @author Gorka Laucirica <[email protected]>
26
 */
27
class WithoutOldPasswordChangeUserPasswordHandler
28
{
29
    /**
30
     * The user password encoder.
31
     *
32
     * @var UserPasswordEncoder
33
     */
34
    private $encoder;
35
36
    /**
37
     * The user repository.
38
     *
39
     * @var UserRepository
40
     */
41
    private $repository;
42
43
    /**
44
     * Constructor.
45
     *
46
     * @param UserRepository      $aRepository The user repository
47
     * @param UserPasswordEncoder $anEncoder   The password encoder
48
     */
49
    public function __construct(UserRepository $aRepository, UserPasswordEncoder $anEncoder)
50
    {
51
        $this->repository = $aRepository;
52
        $this->encoder = $anEncoder;
53
    }
54
55
    /**
56
     * Handles the given command.
57
     *
58
     * @param WithoutOldPasswordChangeUserPasswordCommand $aCommand The command
59
     *
60
     * @throws UserDoesNotExistException when the user does not exist
61
     */
62
    public function __invoke(WithoutOldPasswordChangeUserPasswordCommand $aCommand)
63
    {
64
        $user = $this->repository->userOfEmail(new UserEmail($aCommand->email()));
65
        if (null === $user) {
66
            throw new UserDoesNotExistException();
67
        }
68
        $user->changePassword(UserPassword::fromPlain($aCommand->newPlainPassword(), $this->encoder));
69
70
        $this->repository->persist($user);
71
    }
72
}
73