SendsPasswordResetEmails   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 45
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A sendResetLinkEmail() 0 33 4
1
<?php
2
3
namespace BeyondCode\EmailConfirmation\Traits;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Password;
7
use Illuminate\Validation\ValidationException;
8
9
/**
10
 * Trait SendsPasswordResetEmails
11
 * @package BeyondCode\EmailConfirmation\Traits
12
 */
13
trait SendsPasswordResetEmails
14
{
15
    use \Illuminate\Foundation\Auth\SendsPasswordResetEmails;
16
17
    /**
18
     * Send a reset link to the given user.
19
     *
20
     * @param Request $request
21
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
22
     * @throws ValidationException
23
     */
24
    public function sendResetLinkEmail(Request $request)
25
    {
26
        $this->validateEmail($request);
27
28
        $user = $this->broker()->getUser($request->only('email'));
29
30
        // If the user hasn't confirmed their email address,
31
        // we will throw a validation exception for this error.
32
        // A user can not request a password reset link if they are not confirmed.
33
        if ($user && is_null($user->confirmed_at)) {
34
35
            session(['confirmation_user_id' => $user->getKey()]);
36
37
            throw ValidationException::withMessages([
38
                'confirmation' => [
39
                    __('confirmation::confirmation.not_confirmed_reset_password', [
40
                        'resend_link' => route('auth.resend_confirmation')
41
                    ])
42
                ]
43
            ]);
44
        }
45
46
        // We will send the password reset link to this user. Once we have attempted
47
        // to send the link, we will examine the response then see the message we
48
        // need to show to the user. Finally, we'll send out a proper response.
49
        $response = $this->broker()->sendResetLink(
50
            $request->only('email')
51
        );
52
53
        return $response == Password::RESET_LINK_SENT
54
            ? $this->sendResetLinkResponse($response)
0 ignored issues
show
Bug introduced by
The call to sendResetLinkResponse() misses a required argument $response.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by
$response is of type string, but the function expects a object<Illuminate\Http\Request>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
            : $this->sendResetLinkFailedResponse($request, $response);
56
    }
57
}
58