LoginRequest::authorize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Http\Requests\Auth;
4
5
use Illuminate\Auth\Events\Lockout;
6
use Illuminate\Foundation\Http\FormRequest;
7
use Illuminate\Support\Facades\Auth;
8
use Illuminate\Support\Facades\RateLimiter;
9
use Illuminate\Support\Str;
10
use Illuminate\Validation\ValidationException;
11
12
class LoginRequest extends FormRequest
13
{
14
    /**
15
     * Determine if the user is authorized to make this request.
16
     */
17
    public function authorize(): bool
18
    {
19
        return true;
20
    }
21
22
    /**
23
     * Get the validation rules that apply to the request.
24
     *
25
     * @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
26
     */
27
    public function rules(): array
28
    {
29
        return [
30
            'email' => ['required', 'string', 'email'],
31
            'password' => ['required', 'string'],
32
        ];
33
    }
34
35
    /**
36
     * Attempt to authenticate the request's credentials.
37
     *
38
     * @throws \Illuminate\Validation\ValidationException
39
     */
40
    public function authenticate(): void
41
    {
42
        $this->ensureIsNotRateLimited();
43
44
        if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
0 ignored issues
show
Bug introduced by
The method boolean() does not exist on App\Http\Requests\Auth\LoginRequest. ( Ignorable by Annotation )

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

44
        if (! Auth::attempt($this->only('email', 'password'), $this->/** @scrutinizer ignore-call */ boolean('remember'))) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method only() does not exist on App\Http\Requests\Auth\LoginRequest. ( Ignorable by Annotation )

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

44
        if (! Auth::attempt($this->/** @scrutinizer ignore-call */ only('email', 'password'), $this->boolean('remember'))) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
            RateLimiter::hit($this->throttleKey());
46
47
            throw ValidationException::withMessages([
48
                'email' => trans('auth.failed'),
49
            ]);
50
        }
51
52
        RateLimiter::clear($this->throttleKey());
53
    }
54
55
    /**
56
     * Ensure the login request is not rate limited.
57
     *
58
     * @throws \Illuminate\Validation\ValidationException
59
     */
60
    public function ensureIsNotRateLimited(): void
61
    {
62
        if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
63
            return;
64
        }
65
66
        event(new Lockout($this));
67
68
        $seconds = RateLimiter::availableIn($this->throttleKey());
69
70
        throw ValidationException::withMessages([
71
            'email' => trans('auth.throttle', [
72
                'seconds' => $seconds,
73
                'minutes' => ceil($seconds / 60),
74
            ]),
75
        ]);
76
    }
77
78
    /**
79
     * Get the rate limiting throttle key for the request.
80
     */
81
    public function throttleKey(): string
82
    {
83
        return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip());
0 ignored issues
show
Bug introduced by
The method string() does not exist on App\Http\Requests\Auth\LoginRequest. ( Ignorable by Annotation )

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

83
        return Str::transliterate(Str::lower($this->/** @scrutinizer ignore-call */ string('email')).'|'.$this->ip());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method ip() does not exist on App\Http\Requests\Auth\LoginRequest. ( Ignorable by Annotation )

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

83
        return Str::transliterate(Str::lower($this->string('email')).'|'.$this->/** @scrutinizer ignore-call */ ip());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
84
    }
85
}
86