Completed
Push — master ( 7ec104...6d5219 )
by Sergi Tur
98:33 queued 68:39
created

ResetPasswordController::showResetForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Foundation\Auth\ResetsPasswords;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Password;
9
use Illuminate\Http\JsonResponse;
10
11
class ResetPasswordController extends Controller
12
{
13
    /*
14
    |--------------------------------------------------------------------------
15
    | Password Reset Controller
16
    |--------------------------------------------------------------------------
17
    |
18
    | This controller is responsible for handling password reset requests
19
    | and uses a simple trait to include this behavior. You're free to
20
    | explore this trait and override any methods you wish to tweak.
21
    |
22
    */
23
24
    use ResetsPasswords;
25
26
    /**
27
     * Reset the given user's password.
28
     *
29
     * @param  \Illuminate\Http\Request  $request
30
     * @return \Illuminate\Http\RedirectResponse
31
     */
32
    public function reset(Request $request)
33
    {
34
        $this->validate($request, $this->rules(), $this->validationErrorMessages());
35
36
        // Here we will attempt to reset the user's password. If it is successful we
37
        // will update the password on an actual user model and persist it to the
38
        // database. Otherwise we will parse the error and return the response.
39
        $response = $this->broker()->reset(
40
            $this->credentials($request), function ($user, $password) {
41
            $this->resetPassword($user, $password);
42
        }
43
        );
44
45
        // If the password was successfully reset, we will redirect the user back to
46
        // the application's home authenticated view. If there is an error we can
47
        // redirect them back to where they came from with their error message.
48
        return $response == Password::PASSWORD_RESET
49
            ? $this->sendResetResponse($request, $response)
50
            : $this->sendResetFailedResponse($request, $response);
51
    }
52
53
    /**
54
     * Get the response for a successful password reset.
55
     *
56
     * @param  \Illuminate\Http\Request
57
     * @param  string  $response
58
     * @return \Illuminate\Http\RedirectResponse
59
     */
60 View Code Duplication
    protected function sendResetResponse(Request $request,$response)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62
        if ($request->expectsJson()) {
63
            return response()->json([
64
                'status' => trans($response)
65
            ]);
66
        }
67
        return redirect($this->redirectPath())
68
            ->with('status', trans($response));
69
    }
70
71
    /**
72
     * Get the response for a failed password reset.
73
     *
74
     * @param  \Illuminate\Http\Request
75
     * @param  string  $response
76
     * @return mixed
77
     */
78
    protected function sendResetFailedResponse(Request $request, $response)
79
    {
80
        if ($request->expectsJson()) {
81
            return new JsonResponse(['email' => trans($response) ], 422);
82
        }
83
        return redirect()->back()
84
            ->withInput($request->only('email'))
85
            ->withErrors(['email' => trans($response)]);
86
    }
87
88
    /**
89
     * Display the password reset view for the given token.
90
     *
91
     * If no token is present, display the link request form.
92
     *
93
     * @param  \Illuminate\Http\Request  $request
94
     * @param  string|null  $token
95
     * @return \Illuminate\Http\Response
96
     */
97
    public function showResetForm(Request $request, $token = null)
98
    {
99
        return view('adminlte::auth.passwords.reset')->with(
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
100
            ['token' => $token, 'email' => $request->email]
101
        );
102
    }
103
104
    /**
105
     * Create a new controller instance.
106
     *
107
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
108
     */
109
    public function __construct()
110
    {
111
        $this->middleware('guest');
112
    }
113
}
114