ForgotPasswordFormHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 35
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 22 3
1
<?php namespace Anomaly\UsersModule\User\Password;
2
3
use Anomaly\Streams\Platform\Message\MessageBag;
4
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
5
use Anomaly\UsersModule\User\UserPassword;
6
use Illuminate\Contracts\Config\Repository;
7
8
/**
9
 * Class ForgotPasswordFormHandler
10
 *
11
 * @link          http://pyrocms.com/
12
 * @author        PyroCMS, Inc. <[email protected]>
13
 * @author        Ryan Thompson <[email protected]>
14
 */
15
class ForgotPasswordFormHandler
16
{
17
18
    /**
19
     * Handle the form.
20
     *
21
     * @param ForgotPasswordFormBuilder $builder
22
     * @param UserRepositoryInterface   $users
23
     * @param UserPassword              $password
24
     * @param MessageBag                $messages
25
     * @param Repository                $config
26
     */
27
    public function handle(
28
        ForgotPasswordFormBuilder $builder,
29
        UserRepositoryInterface $users,
30
        UserPassword $password,
31
        MessageBag $messages,
32
        Repository $config
33
    ) {
34
        if ($builder->hasFormErrors()) {
35
            return;
36
        }
37
38
        $user = $users->findByEmail($builder->getFormValue('email'));
39
40
        if ($path = $builder->getFormOption('reset_path')) {
41
            $config->set('anomaly.module.users::paths.reset', $path);
42
        }
43
44
        $password->forgot($user);
45
        $password->send($user, $builder->getFormOption('reset_redirect'));
46
47
        $messages->success('anomaly.module.users::message.confirm_reset_password');
48
    }
49
}
50