BeginResetProcessCommandHandler::findUser()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6667
cc 2
eloc 5
nc 2
nop 1
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