Completed
Push — develop ( 4e1646...0038a1 )
by Abdelrahman
02:00
created

AccountTwoFactorPhoneRequest::withValidator()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.2
cc 4
eloc 5
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Auth\Http\Requests\Adminarea;
6
7
use Illuminate\Foundation\Http\FormRequest;
8
9
class AccountTwoFactorPhoneRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @throws \Cortex\Foundation\Exceptions\GenericException
15
     *
16
     * @return bool
17
     */
18
    public function authorize(): bool
19
    {
20
        return true;
21
    }
22
23
    /**
24
     * Configure the validator instance.
25
     *
26
     * @param \Illuminate\Validation\Validator $validator
27
     *
28
     * @return void
29
     */
30
    public function withValidator($validator): void
31
    {
32
        $user = $this->user($this->route('guard'));
33
34
        $validator->after(function ($validator) use ($user) {
35
            if (! $user->phone || ! $user->phone_verified) {
36
                $validator->errors()->add('phone', trans('cortex/auth::messages.account.'.(! $user->phone ? 'phone_field_required' : 'phone_verification_required')));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 166 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
37
            }
38
        });
39
    }
40
41
    /**
42
     * Get the validation rules that apply to the request.
43
     *
44
     * @return array
45
     */
46
    public function rules(): array
47
    {
48
        return [];
49
    }
50
}
51