Completed
Pull Request — master (#7)
by
unknown
01:25
created

ResetsPasswords   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 46
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B reset() 0 35 3
1
<?php
2
3
namespace BeyondCode\EmailConfirmation\Traits;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Password;
7
8
trait ResetsPasswords
9
{
10
    use \Illuminate\Foundation\Auth\ResetsPasswords;
11
12
    /**
13
     * Reset the given user's password.
14
     *
15
     * @param  \Illuminate\Http\Request  $request
16
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
17
     */
18
    public function reset(Request $request)
19
    {
20
        $this->validate($request, $this->rules(), $this->validationErrorMessages());
0 ignored issues
show
Bug introduced by
It seems like validate() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
21
22
        $user = $this->broker()->getUser($this->credentials($request));
23
24
        // If the user hasn't confirmed their email address,
25
        // we will redirect them back with their error message.
26
        if (is_null($user->confirmed_at)) {
27
28
            session(['confirmation_user_id' => $user->getKey()]);
29
30
            return redirect()->back()->with(
31
                'confirmation', __('confirmation::confirmation.not_confirmed', [
32
                    'resend_link' => route('auth.resend_confirmation')
33
                ])
34
            );
35
        }
36
37
        // Here we will attempt to reset the user's password. If it is successful we
38
        // will update the password on an actual user model and persist it to the
39
        // database. Otherwise we will parse the error and return the response.
40
        $response = $this->broker()->reset(
41
            $this->credentials($request), function ($user, $password) {
42
            $this->resetPassword($user, $password);
43
        }
44
        );
45
46
        // If the password was successfully reset, we will redirect the user back to
47
        // the application's home authenticated view. If there is an error we can
48
        // redirect them back to where they came from with their error message.
49
        return $response == Password::PASSWORD_RESET
50
            ? $this->sendResetResponse($response)
51
            : $this->sendResetFailedResponse($request, $response);
52
    }
53
}