CompleteResetProcessCommandHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 12 2
A findUser() 0 9 2
1
<?php namespace Modules\User\Commands\Handlers;
2
3
use Modules\Core\Contracts\Authentication;
4
use Modules\User\Exceptions\InvalidOrExpiredResetCode;
5
use Modules\User\Exceptions\UserNotFoundException;
6
use Modules\User\Repositories\UserRepository;
7
8
class CompleteResetProcessCommandHandler
9
{
10
    protected $input;
11
    /**
12
     * @var UserRepository
13
     */
14
    private $user;
15
    /**
16
     * @var Authentication
17
     */
18
    private $auth;
19
20
    public function __construct(UserRepository $user, Authentication $auth)
21
    {
22
        $this->user = $user;
23
        $this->auth = $auth;
24
    }
25
26
    /**
27
     * Handle the command
28
     *
29
     * @param $command
30
     * @throws InvalidOrExpiredResetCode
31
     * @throws UserNotFoundException
32
     * @return mixed
33
     */
34
    public function handle($command)
35
    {
36
        $this->input = $command;
37
38
        $user = $this->findUser();
39
40
        if (!$this->auth->completeResetPassword($user, $this->input->code, $this->input->password)) {
41
            throw new InvalidOrExpiredResetCode();
42
        }
43
44
        return $user;
45
    }
46
47
    public function findUser()
48
    {
49
        $user = $this->user->find($this->input->userId);
50
        if ($user) {
51
            return $user;
52
        }
53
54
        throw new UserNotFoundException();
55
    }
56
}
57