Completed
Pull Request — master (#12)
by
unknown
04:26 queued 59s
created

PasswordResetHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 5
Bugs 1 Features 2
Metric Value
wmc 3
c 5
b 1
f 2
lcom 1
cbo 4
dl 0
loc 38
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
    /**
16
     * PasswordResetHandler constructor.
17
     *
18
     * @param UserRepositoryCollection $userRepositoryCollection
19
     */
20
    public function __construct(UserRepositoryCollection $userRepositoryCollection)
21
    {
22
        $this->userRepositoryCollection = $userRepositoryCollection;
23
    }
24
25
    /**
26
     * @param ResetPassword $command
27
     *
28
     * @throws InvalidPasswordConfirmationException
29
     */
30
    public function handle(ResetPassword $command)
31
    {
32
        if (!$command->passwordConfirmationIsValid()) {
33
            throw new InvalidPasswordConfirmationException('The password confirmation isn\'t valid');
34
        }
35
        
36
        $user = $command->getUser();
37
        $updatedUser = clone $user;
38
        $updatedUser->setPassword($command->getPassword());
39
        $updatedUser->clearPasswordResetToken();
40
        $repository = $this->userRepositoryCollection->findRepositoryByClassName(get_class($user));
41
        $repository->update($user, $updatedUser);
42
43
        return;
44
    }
45
}
46