Completed
Pull Request — master (#17)
by Fèvre
02:48
created

ForgotPasswordController::sendResetLinkResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

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 4
nc 1
nop 1
1
<?php
2
namespace Xetaravel\Http\Controllers\Auth;
3
4
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
5
use Illuminate\Http\Request;
6
use Illuminate\Http\RedirectResponse;
7
use Illuminate\Support\Facades\Password;
8
use Illuminate\View\View;
9
use Xetaravel\Http\Controllers\Controller;
10
use Xetaravel\Models\Validators\PasswordResetValidator;
11
12
class ForgotPasswordController extends Controller
13
{
14
    /*
15
    |--------------------------------------------------------------------------
16
    | Password Reset Controller
17
    |--------------------------------------------------------------------------
18
    |
19
    | This controller is responsible for handling password reset emails and
20
    | includes a trait which assists in sending these notifications from
21
    | your application to your users. Feel free to explore this trait.
22
    |
23
    */
24
    use SendsPasswordResetEmails;
25
26
    /**
27
     * Create a new controller instance.
28
     *
29
     * @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...
30
     */
31
    public function __construct()
32
    {
33
        $this->middleware('guest');
34
    }
35
36
    /**
37
     * Display the form to request a password reset link.
38
     *
39
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be View?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
40
     */
41
    public function showLinkRequestForm(): View
42
    {
43
        return view('Auth.passwords.email');
44
    }
45
46
    /**
47
     * Send a reset link to the given user.
48
     *
49
     * @param \Illuminate\Http\Request $request
50
     *
51
     * @return \Illuminate\Http\RedirectResponse
52
     */
53
    public function sendResetLinkEmail(Request $request): RedirectResponse
54
    {
55
        PasswordResetValidator::validateEmail($request->all())->validate();
56
57
        // We will send the password reset link to this user. Once we have attempted
58
        // to send the link, we will examine the response then see the message we
59
        // need to show to the user. Finally, we'll send out a proper response.
60
        $response = $this->broker()->sendResetLink(
61
            $request->only('email')
62
        );
63
64
        return $response == Password::RESET_LINK_SENT
65
                    ? $this->sendResetLinkResponse($response)
66
                    : $this->sendResetLinkFailedResponse($request, $response);
67
    }
68
69
    /**
70
     * Get the response for a successful password reset link.
71
     *
72
     * @param string $response
73
     *
74
     * @return \Illuminate\Http\RedirectResponse
75
     */
76
    protected function sendResetLinkResponse($response): RedirectResponse
0 ignored issues
show
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
    {
78
        return redirect()
79
            ->route('page.index')
80
            ->with('success', 'We have e-mailed your password reset link!');
81
    }
82
}
83