BeginResetProcessCommandHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 8 1
A findUser() 0 9 2
1
<?php namespace Modules\User\Commands\Handlers;
2
3
use Illuminate\Support\Facades\Event;
4
use Modules\Core\Contracts\Authentication;
5
use Modules\User\Events\UserHasBegunResetProcess;
6
use Modules\User\Exceptions\UserNotFoundException;
7
use Modules\User\Repositories\UserRepository;
8
9
class BeginResetProcessCommandHandler
10
{
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 UserNotFoundException
31
     * @return mixed
32
     */
33
    public function handle($command)
34
    {
35
        $user = $this->findUser((array) $command);
36
37
        $code = $this->auth->createReminderCode($user);
38
39
        event(new UserHasBegunResetProcess($user, $code));
40
    }
41
42
    private function findUser($credentials)
43
    {
44
        $user = $this->user->findByCredentials((array) $credentials);
45
        if ($user) {
46
            return $user;
47
        }
48
49
        throw new UserNotFoundException();
50
    }
51
}
52