ResetsPasswords   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A reset() 0 16 3
A showResetForm() 0 8 2
1
<?php
2
3
namespace Slides\Connector\Auth\Concerns;
4
5
use Illuminate\Http\Request;
6
use Slides\Connector\Auth\Facades\AuthService;
7
use Illuminate\Auth\Passwords\PasswordBroker;
8
use Illuminate\Foundation\Auth\ResetsPasswords as BaseResetsPassword;
9
10
/**
11
 * Trait SendsPasswordResetEmails
12
 *
13
 * @package Slides\Connector\Auth\Concerns
14
 */
15
trait ResetsPasswords
16
{
17
    use BaseResetsPassword;
18
19
    /**
20
     * Display the password reset view for the given token.
21
     *
22
     * If no token is present, display the link request form.
23
     *
24
     * @param string $token
25
     * @param string $email
26
     *
27
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
28
     */
29
    public function showResetForm(string $token, string $email)
30
    {
31
        if(!$email = AuthService::validatePasswordResetToken($token, $email)) {
0 ignored issues
show
Bug introduced by
The method validatePasswordResetToken() does not exist on Slides\Connector\Auth\Facades\AuthService. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

31
        if(!$email = AuthService::/** @scrutinizer ignore-call */ validatePasswordResetToken($token, $email)) {
Loading history...
32
            throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
33
        }
34
35
        return view('auth.passwords.reset')->with(
36
            ['token' => $token, 'email' => $email]
37
        );
38
    }
39
40
    /**
41
     * Reset user's password
42
     *
43
     * @param Request $request
44
     *
45
     * @return \Illuminate\Http\RedirectResponse
46
     */
47
    public function reset(Request $request)
48
    {
49
        $this->validate($request, $this->rules(), $this->validationErrorMessages());
0 ignored issues
show
Bug introduced by
It seems like validate() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

49
        $this->/** @scrutinizer ignore-call */ 
50
               validate($request, $this->rules(), $this->validationErrorMessages());
Loading history...
50
51
        if(AuthService::resetPassword(
0 ignored issues
show
Bug introduced by
The method resetPassword() does not exist on Slides\Connector\Auth\Facades\AuthService. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

51
        if(AuthService::/** @scrutinizer ignore-call */ resetPassword(
Loading history...
52
            $request->input('token'),
53
            $email = $request->input('email'),
54
            $password = $request->input('password'),
55
            $request->input('password_confirmation')
56
        )) {
57
            if(AuthService::login($email, $password)) {
0 ignored issues
show
Bug introduced by
The method login() does not exist on Slides\Connector\Auth\Facades\AuthService. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

57
            if(AuthService::/** @scrutinizer ignore-call */ login($email, $password)) {
Loading history...
58
                return $this->sendResetResponse(PasswordBroker::PASSWORD_RESET);
0 ignored issues
show
Bug introduced by
The call to Slides\Connector\Auth\Co...ds::sendResetResponse() has too few arguments starting with response. ( Ignorable by Annotation )

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

58
                return $this->/** @scrutinizer ignore-call */ sendResetResponse(PasswordBroker::PASSWORD_RESET);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
Illuminate\Auth\Password...dBroker::PASSWORD_RESET of type string is incompatible with the type Illuminate\Http\Request expected by parameter $request of Slides\Connector\Auth\Co...ds::sendResetResponse(). ( Ignorable by Annotation )

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

58
                return $this->sendResetResponse(/** @scrutinizer ignore-type */ PasswordBroker::PASSWORD_RESET);
Loading history...
59
            }
60
        }
61
62
        return $this->sendResetFailedResponse($request, PasswordBroker::INVALID_PASSWORD);
63
    }
64
}