Completed
Push — develop ( 5abd4c...dae2aa )
by Abdelrahman
09:07
created

AccountSettingsRequest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 4 1
B prepareForValidation() 0 27 6
A rules() 0 7 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 AccountSettingsRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @return bool
15
     */
16
    public function authorize(): bool
17
    {
18
        return true;
19
    }
20
21
    /**
22
     * Prepare the data for validation.
23
     *
24
     * @return void
25
     */
26
    protected function prepareForValidation(): void
27
    {
28
        $data = $this->all();
29
30
        $country = $data['country_code'] ?? null;
31
        $email = $data['email'] ?? null;
32
        $phone = $data['phone'] ?? null;
33
        $user = $this->user($this->get('guard'));
34
        $twoFactor = $user->getTwoFactor();
35
36
        if ($email !== $user->email) {
37
            $data['email_verified'] = false;
38
            $data['email_verified_at'] = null;
39
        }
40
41
        if ($phone !== $user->phone) {
42
            $data['phone_verified'] = false;
43
            $data['phone_verified_at'] = null;
44
        }
45
46
        if ($twoFactor && (isset($data['phone_verified']) || $country !== $user->country_code)) {
47
            array_set($twoFactor, 'phone.enabled', false);
48
            $data['two_factor'] = $twoFactor;
49
        }
50
51
        $this->replace($data);
52
    }
53
54
    /**
55
     * Get the validation rules that apply to the request.
56
     *
57
     * @return array
58
     */
59
    public function rules(): array
60
    {
61
        $user = $this->user($this->get('guard'));
62
        $user->updateRulesUniques();
63
64
        return $user->getRules();
65
    }
66
}
67