Completed
Pull Request — master (#12)
by
unknown
04:36 queued 01:22
created

ResetPasswordHandler::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 2
eloc 8
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 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