GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 8eeb44...50e745 )
by Pascal
10:47
created

CurrentPassword::passes()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 12
rs 10
1
<?php
2
3
namespace ProtoneMedia\LaravelMixins\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Foundation\Auth\ThrottlesLogins;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\Hash;
9
use Illuminate\Support\Str;
10
11
class CurrentPassword implements Rule
12
{
13
    use ThrottlesLogins;
0 ignored issues
show
introduced by
The trait Illuminate\Foundation\Auth\ThrottlesLogins requires some properties which are not provided by ProtoneMedia\LaravelMixins\Rules\CurrentPassword: $maxAttempts, $decayMinutes
Loading history...
14
15
    private bool $tooManyAttempts = false;
16
17
    /**
18
     * Get the throttle key for the given request.
19
     *
20
     * @param  \Illuminate\Http\Request  $request
21
     * @return string
22
     */
23
    protected function throttleKey(Request $request)
24
    {
25
        return Str::lower($request->user()->getAuthIdentifier() . '|' . $request->ip());
26
    }
27
28
    /**
29
     * Determine if the validation rule passes.
30
     *
31
     * @param  string  $attribute
32
     * @param  mixed  $value
33
     * @return bool
34
     */
35
    public function passes($attribute, $value)
36
    {
37
        $request = request();
38
39
        if ($this->hasTooManyLoginAttempts($request)) {
40
            $this->tooManyAttempts = true;
41
            return false;
42
        }
43
44
        return tap(
45
            Hash::check($value, $request->user()->getAuthPassword()),
46
            fn ($verified) => $verified ? null : $this->incrementLoginAttempts($request)
47
        );
48
    }
49
50
    /**
51
     * Get the validation error message.
52
     *
53
     * @return string
54
     */
55
    public function message()
56
    {
57
        if ($this->tooManyAttempts) {
58
            $seconds = $this->limiter()->availableIn(
59
                $this->throttleKey(request())
60
            );
61
62
            return __('auth.throttle', [
63
                'seconds' => $seconds,
64
                'minutes' => ceil($seconds / 60),
65
            ]);
66
        }
67
68
        return __('validation.password');
69
    }
70
}
71