Code Duplication    Length = 46-50 lines in 2 locations

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

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

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