Conditions | 17 |
Paths | 256 |
Total Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
29 | protected function prepareForValidation(): void |
||
30 | { |
||
31 | $data = $this->all(); |
||
32 | |||
33 | $admin = $this->route('admin') ?? app('cortex.auth.admin'); |
||
34 | $country = $data['country_code'] ?? null; |
||
35 | $twoFactor = $admin->getTwoFactor(); |
||
36 | |||
37 | $data['email_verified'] = $this->get('email_verified', false); |
||
38 | $data['phone_verified'] = $this->get('phone_verified', false); |
||
39 | |||
40 | if ($admin->exists && empty($data['password'])) { |
||
41 | unset($data['password'], $data['password_confirmation']); |
||
42 | } |
||
43 | |||
44 | // Update email verification date |
||
45 | if ($data['email_verified'] && $admin->email_verified !== $data['email_verified']) { |
||
46 | $data['email_verified_at'] = now(); |
||
47 | } |
||
48 | |||
49 | // Update phone verification date |
||
50 | if ($data['phone_verified'] && $admin->phone_verified !== $data['phone_verified']) { |
||
51 | $data['phone_verified_at'] = now(); |
||
52 | } |
||
53 | |||
54 | // Set abilities |
||
55 | if (! empty($data['abilities'])) { |
||
56 | if ($this->user($this->route('guard'))->can('grant', \Cortex\Auth\Models\Ability::class)) { |
||
57 | $abilities = array_map('intval', $this->get('abilities', [])); |
||
58 | $data['abilities'] = $this->user($this->route('guard'))->can('superadmin') ? $abilities |
||
59 | : $this->user($this->route('guard'))->getAbilities()->pluck('id')->intersect($abilities)->toArray(); |
||
60 | } else { |
||
61 | unset($data['abilities']); |
||
62 | } |
||
63 | } |
||
64 | |||
65 | // Set roles |
||
66 | if (! empty($data['roles'])) { |
||
67 | if ($data['roles'] && $this->user($this->route('guard'))->can('assign', \Cortex\Auth\Models\Role::class)) { |
||
68 | $roles = array_map('intval', $this->get('roles', [])); |
||
69 | $data['roles'] = $this->user($this->route('guard'))->can('superadmin') ? $roles |
||
70 | : $this->user($this->route('guard'))->roles->pluck('id')->intersect($roles)->toArray(); |
||
71 | } else { |
||
72 | unset($data['roles']); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | if ($twoFactor && (isset($data['phone_verified_at']) || $country !== $admin->country_code)) { |
||
77 | array_set($twoFactor, 'phone.enabled', false); |
||
78 | $data['two_factor'] = $twoFactor; |
||
79 | } |
||
80 | |||
81 | $this->replace($data); |
||
82 | } |
||
83 | |||
117 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.