NewPasswordController::store()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 32
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 16
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 32
rs 9.7333
1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Auth\Events\PasswordReset;
7
use Illuminate\Http\RedirectResponse;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Hash;
10
use Illuminate\Support\Facades\Password;
11
use Illuminate\Support\Str;
12
use Illuminate\Validation\Rules;
13
use Illuminate\Validation\ValidationException;
14
use Inertia\Inertia;
15
use Inertia\Response;
16
17
class NewPasswordController extends Controller
18
{
19
    /**
20
     * Display the password reset view.
21
     */
22
    public function create(Request $request): Response
23
    {
24
        return Inertia::render('Auth/ResetPassword', [
25
            'email' => $request->email,
0 ignored issues
show
Bug introduced by
The property email does not seem to exist on Illuminate\Http\Request.
Loading history...
26
            'token' => $request->route('token'),
0 ignored issues
show
Bug introduced by
The method route() does not exist on Illuminate\Http\Request. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
            'token' => $request->/** @scrutinizer ignore-call */ route('token'),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
        ]);
28
    }
29
30
    /**
31
     * Handle an incoming new password request.
32
     *
33
     * @throws \Illuminate\Validation\ValidationException
34
     */
35
    public function store(Request $request): RedirectResponse
36
    {
37
        $request->validate([
0 ignored issues
show
Bug introduced by
The method validate() does not exist on Illuminate\Http\Request. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        $request->/** @scrutinizer ignore-call */ 
38
                  validate([

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
            'token' => 'required',
39
            'email' => 'required|email',
40
            'password' => ['required', 'confirmed', Rules\Password::defaults()],
41
        ]);
42
43
        // Here we will attempt to reset the user's password. If it is successful we
44
        // will update the password on an actual user model and persist it to the
45
        // database. Otherwise we will parse the error and return the response.
46
        $status = Password::reset(
47
            $request->only('email', 'password', 'password_confirmation', 'token'),
0 ignored issues
show
Bug introduced by
The method only() does not exist on Illuminate\Http\Request. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
            $request->/** @scrutinizer ignore-call */ 
48
                      only('email', 'password', 'password_confirmation', 'token'),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
            function ($user) use ($request) {
49
                $user->forceFill([
50
                    'password' => Hash::make($request->password),
0 ignored issues
show
Bug introduced by
The property password does not seem to exist on Illuminate\Http\Request.
Loading history...
51
                    'remember_token' => Str::random(60),
52
                ])->save();
53
54
                event(new PasswordReset($user));
55
            }
56
        );
57
58
        // If the password was successfully reset, we will redirect the user back to
59
        // the application's home authenticated view. If there is an error we can
60
        // redirect them back to where they came from with their error message.
61
        if ($status == Password::PASSWORD_RESET) {
62
            return redirect()->route('login')->with('status', __($status));
63
        }
64
65
        throw ValidationException::withMessages([
66
            'email' => [trans($status)],
67
        ]);
68
    }
69
}
70