Completed
Pull Request — master (#12)
by
unknown
02:46
created

PasswordResetHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 3
c 2
b 1
f 1
lcom 1
cbo 4
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 15 2
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 PasswordReset $command
22
     *
23
     * @throws InvalidPasswordConfirmationException
24
     */
25
    public function handle(PasswordReset $command)
26
    {
27
        if ($command->passwordConfirmationIsValid()) {
28
            $user = $command->getUser();
29
            $updatedUser = clone $user;
30
            $updatedUser->setPassword($command->getPassword());
31
            $updatedUser->clearPasswordResetToken();
32
            $repository = $this->userRepositoryCollection->findRepositoryByClassName(get_class($user));
33
            $repository->update($user, $updatedUser);
34
35
            return;
36
        }
37
38
        throw new InvalidPasswordConfirmationException('The password confirmation isn\'t valid');
39
    }
40
}
41