Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 6a87fb...a42a1b )
by Cristian
15:19 queued 07:45
created

SendsPasswordResetEmails::showLinkRequestForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Library\Auth;
4
5
use Illuminate\Http\JsonResponse;
6
use Illuminate\Http\Request;
7
use Illuminate\Support\Facades\Password;
8
use Illuminate\Validation\ValidationException;
9
10
trait SendsPasswordResetEmails
11
{
12
    /**
13
     * Display the form to request a password reset link.
14
     *
15
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

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...
16
     */
17
    public function showLinkRequestForm()
18
    {
19
        return view('auth.passwords.email');
20
    }
21
22
    /**
23
     * Send a reset link to the given user.
24
     *
25
     * @param  \Illuminate\Http\Request  $request
26
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
27
     */
28
    public function sendResetLinkEmail(Request $request)
29
    {
30
        $this->validateEmail($request);
31
32
        // We will send the password reset link to this user. Once we have attempted
33
        // to send the link, we will examine the response then see the message we
34
        // need to show to the user. Finally, we'll send out a proper response.
35
        $response = $this->broker()->sendResetLink(
36
            $this->credentials($request)
37
        );
38
39
        return $response == Password::RESET_LINK_SENT
40
                    ? $this->sendResetLinkResponse($request, $response)
41
                    : $this->sendResetLinkFailedResponse($request, $response);
42
    }
43
44
    /**
45
     * Validate the email for the given request.
46
     *
47
     * @param  \Illuminate\Http\Request  $request
48
     * @return void
49
     */
50
    protected function validateEmail(Request $request)
51
    {
52
        $request->validate(['email' => 'required|email']);
53
    }
54
55
    /**
56
     * Get the needed authentication credentials from the request.
57
     *
58
     * @param  \Illuminate\Http\Request  $request
59
     * @return array
60
     */
61
    protected function credentials(Request $request)
62
    {
63
        return $request->only('email');
64
    }
65
66
    /**
67
     * Get the response for a successful password reset link.
68
     *
69
     * @param  \Illuminate\Http\Request  $request
70
     * @param  string  $response
71
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
72
     */
73
    protected function sendResetLinkResponse(Request $request, $response)
74
    {
75
        return $request->wantsJson()
76
                    ? new JsonResponse(['message' => trans($response)], 200)
77
                    : back()->with('status', trans($response));
78
    }
79
80
    /**
81
     * Get the response for a failed password reset link.
82
     *
83
     * @param  \Illuminate\Http\Request  $request
84
     * @param  string  $response
85
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
86
     */
87 View Code Duplication
    protected function sendResetLinkFailedResponse(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...
88
    {
89
        if ($request->wantsJson()) {
90
            throw ValidationException::withMessages([
91
                'email' => [trans($response)],
92
            ]);
93
        }
94
95
        return back()
96
                ->withInput($request->only('email'))
97
                ->withErrors(['email' => trans($response)]);
98
    }
99
100
    /**
101
     * Get the broker to be used during password reset.
102
     *
103
     * @return \Illuminate\Contracts\Auth\PasswordBroker
104
     */
105
    public function broker()
106
    {
107
        return Password::broker();
108
    }
109
}
110