Completed
Pull Request — master (#12)
by
unknown
06:06 queued 01:12
created

PasswordResetHandler::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 15
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\Command;
4
5
use SumoCoders\FrameworkMultiUserBundle\Exception\InvalidPasswordConfirmationException;
6
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection;
7
8
class PasswordResetHandler
9
{
10
    /**
11
     * @var UserRepositoryCollection
12
     */
13
    private $userRepositoryCollection;
14
15
    public function __construct(UserRepositoryCollection $userRepositoryCollection)
16
    {
17
        $this->userRepositoryCollection = $userRepositoryCollection;
18
    }
19
20
    /**
21
     * @param ResetPassword $command
22
     *
23
     * @throws InvalidPasswordConfirmationException
24
     */
25
    public function handle(ResetPassword $command)
26
    {
27
        if (!$command->passwordConfirmationIsValid()) {
28
            throw new InvalidPasswordConfirmationException('The password confirmation isn\'t valid');
29
        }
30
        
31
        $user = $command->getUser();
32
        $updatedUser = clone $user;
33
        $updatedUser->setPassword($command->getPassword());
34
        $updatedUser->clearPasswordResetToken();
35
        $repository = $this->userRepositoryCollection->findRepositoryByClassName(get_class($user));
36
        $repository->update($user, $updatedUser);
37
38
        return;
39
    }
40
}
41