ResetPassword::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 10
nc 3
nop 1
1
<?php namespace Anomaly\UsersModule\User\Password\Command;
2
3
use Anomaly\UsersModule\User\Contract\UserInterface;
4
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
5
6
7
/**
8
 * Class ResetPassword
9
 *
10
 * @link          http://pyrocms.com/
11
 * @author        PyroCMS, Inc. <[email protected]>
12
 * @author        Ryan Thompson <[email protected]>
13
 */
14
class ResetPassword
15
{
16
17
    /**
18
     * The user instance.
19
     *
20
     * @var UserInterface
21
     */
22
    protected $user;
23
24
    /**
25
     * The password reset code.
26
     *
27
     * @var string
28
     */
29
    protected $code;
30
31
    /**
32
     * The password desired.
33
     *
34
     * @var string
35
     */
36
    protected $password;
37
38
    /**
39
     * Create a new ResetPasswordReset instance.
40
     *
41
     * @param UserInterface $user
42
     * @param               $code
43
     * @param               $password
44
     */
45
    function __construct(UserInterface $user, $code, $password)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
46
    {
47
        $this->user     = $user;
48
        $this->code     = $code;
49
        $this->password = $password;
50
    }
51
52
    /**
53
     * Handle the command.
54
     *
55
     * @param  UserRepositoryInterface $users
56
     * @return bool
57
     */
58
    public function handle(UserRepositoryInterface $users)
59
    {
60
        $user = $users->findByResetCode($this->code);
61
62
        if (!$user) {
63
            return false;
64
        }
65
66
        if ($user->getId() !== $this->user->getId()) {
67
            return false;
68
        }
69
70
        $this->user->setAttribute('reset_code', null);
71
        $this->user->setAttribute('password', $this->password);
72
73
        $users->save($this->user);
74
75
        return true;
76
    }
77
}
78