Completed
Pull Request — master (#12)
by
unknown
07:31 queued 04:16
created

ResetPasswordHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 12 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 ResetPasswordHandler
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
        $user->setPassword($command->getPassword());
38
        $user->clearPasswordResetToken();
39
        $repository = $this->userRepositoryCollection->findRepositoryByClassName(get_class($user));
40
        $repository->update($user, $user);
0 ignored issues
show
Unused Code introduced by
The call to UserRepository::update() has too many arguments starting with $user.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
41
    }
42
}
43