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

PasswordResetRequestHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A handle() 0 9 1
A sendPasswordResetToken() 0 5 1
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\Command;
4
5
use SumoCoders\FrameworkMultiUserBundle\Event\PasswordResetTokenCreated;
6
use SumoCoders\FrameworkMultiUserBundle\User\PasswordReset as UserPasswordReset;
7
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection;
8
use Swift_Mailer;
9
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
10
11
class PasswordResetRequestHandler
12
{
13
    /**
14
     * @var UserRepositoryCollection
15
     */
16
    private $userRepositoryCollection;
17
18
    /**
19
     * @var EventDispatcher
20
     */
21
    private $dispatcher;
22
23
    /**
24
     * PasswordResetRequestHandler constructor.
25
     *
26
     * @param UserRepositoryCollection $userRepositoryCollection
27
     * @param EventDispatcherInterface $dispatcher
28
     */
29
    public function __construct(
30
        UserRepositoryCollection $userRepositoryCollection,
31
        EventDispatcherInterface $dispatcher
32
    ) {
33
        $this->userRepositoryCollection = $userRepositoryCollection;
34
        $this->dispatcher = $dispatcher;
0 ignored issues
show
Documentation Bug introduced by
It seems like $dispatcher of type object<Symfony\Component...entDispatcherInterface> is incompatible with the declared type object<SumoCoders\Framew...ommand\EventDispatcher> of property $dispatcher.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35
    }
36
37
    /**
38
     * Creates a password reset token and sends an email to the user.
39
     *
40
     * @param RequestPasswordReset $command
41
     *
42
     * @return int
43
     */
44
    public function handle(RequestPasswordReset $command)
45
    {
46
        $user = $command->getUser();
47
        $user->generatePasswordResetToken();
48
        $repository = $this->userRepositoryCollection->findRepositoryByClassName(get_class($user));
49
        $repository->save($user);
50
51
        $this->sendPasswordResetToken($user);
0 ignored issues
show
Documentation introduced by
$user is of type object<SumoCoders\Framew...dle\User\UserInterface>, but the function expects a object<SumoCoders\Framew...dle\User\PasswordReset>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
    }
53
54
    /**
55
     * Sends the password reset token to the user.
56
     *
57
     * @param UserPasswordReset $user
58
     *
59
     * @return int
60
     */
61
    private function sendPasswordResetToken(UserPasswordReset $user)
62
    {
63
        $event = new PasswordResetTokenCreated($user);
64
        $this->dispatcher->dispatch('multi_user.event.password_reset_token_created', $event);
65
    }
66
}
67