Conditions | 20 |
Paths | 1 |
Total Lines | 42 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
72 | protected function defineGates(): void |
||
73 | { |
||
74 | Gate::define('view-assessment-plan', function ($user, $jobPoster) { |
||
75 | return $user->isAdmin() || |
||
76 | $user->isManager() && $jobPoster->manager->user_id === $user->id; |
||
77 | }); |
||
78 | |||
79 | /* Logged-in Users can view themselves. Admins can view themselves, |
||
80 | * Managers/HR Advisors and Applicants but not other Admins. Managers can view |
||
81 | * Applicants of their Job Posters. HR Advisors can view Managers |
||
82 | * within their department, and any Applicants of Job Posters created |
||
83 | * by those managers. |
||
84 | */ |
||
85 | |||
86 | /* TODO: User roles/permissions are getting a little unruly. I needed to add an |
||
87 | * additional check alongside isUpgradedManager() because we have an isAdmin() |
||
88 | * passthrough on that method, which was causing issues on the hr_advisor/manager |
||
89 | * reference. |
||
90 | */ |
||
91 | Gate::define('view-user', function ($user, $userProfile) { |
||
92 | return ( |
||
93 | $user->id === $userProfile->id |
||
94 | ) || |
||
95 | ( |
||
96 | $user->isAdmin() && |
||
97 | !$userProfile->isAdmin() |
||
98 | ) || |
||
99 | ( |
||
100 | ($user->isHrAdvisor() && !$userProfile->isAdmin() && $userProfile->isUpgradedManager()) && |
||
101 | ($user->hr_advisor->department_id === $userProfile->manager->department_id) |
||
102 | ) || |
||
103 | ( |
||
104 | ($user->isHrAdvisor() && $userProfile->isApplicant()) && |
||
105 | $user->can('claimsJobApplicantAppliedTo', $userProfile->applicant) |
||
106 | ) || |
||
107 | ( |
||
108 | (!$user->isAdmin() && $user->isUpgradedManager() && $userProfile->isApplicant()) && |
||
109 | $user->can('ownsJobApplicantAppliedTo', $userProfile->applicant) |
||
110 | ) || |
||
111 | ( |
||
112 | ($user->isApplicant() && !$userProfile->isAdmin() && $userProfile->isUpgradedManager()) && |
||
113 | $userProfile->can('ownsJobApplicantAppliedTo', $user->applicant) |
||
114 | ); |
||
134 |