| Conditions | 10 |
| Paths | 19 |
| Total Lines | 38 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 19 |
| CRAP Score | 10.2537 |
| 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 |
||
| 23 | 18 | public function handle($request, Closure $next) |
|
|
1 ignored issue
–
show
|
|||
| 24 | { |
||
| 25 | 18 | if (Auth::check()) { |
|
| 26 | 10 | $user = Auth::user(); |
|
| 27 | |||
| 28 | //If running in a local environment, and FORCE_ADMIN is true, |
||
| 29 | //automatically set any logged in user to (temporarilly) be an admin |
||
| 30 | 10 | if (App::environment() == 'local' && Config::get('app.force_admin')) { |
|
| 31 | $adminRole = UserRole::where('name', 'admin')->firstOrFail(); |
||
| 32 | $user->user_role_id = $adminRole->id; |
||
| 33 | // $user->user_role = $adminRole; |
||
| 34 | $user->save(); |
||
| 35 | } |
||
| 36 | |||
| 37 | //Ensure the user has a proper profile associated with it |
||
| 38 | //If no profile exists yet create one. |
||
| 39 | //Admins should be given an applicant and manager profile |
||
| 40 | 10 | if ($user->hasRole('applicant') || |
|
| 41 | 10 | $user->hasRole('admin') ) { |
|
| 42 | 4 | $applicantProfile = $user->applicant; |
|
| 43 | 4 | if ($applicantProfile === null) { |
|
| 44 | 1 | $applicantProfile = new Applicant(); |
|
| 45 | 1 | $applicantProfile->user_id = $user->id; |
|
| 46 | 1 | $applicantProfile->save(); |
|
| 47 | } |
||
| 48 | } |
||
| 49 | 10 | if ($user->hasRole('manager') || |
|
| 50 | 10 | $user->hasRole('admin')) { |
|
| 51 | 7 | $managerProfile = $user->manager; |
|
| 52 | 7 | if ($managerProfile === null) { |
|
| 53 | 1 | $managerProfile = new Manager(); |
|
| 54 | 1 | $managerProfile->user_id = $user->id; |
|
| 55 | 1 | $managerProfile->save(); |
|
| 56 | } |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | 18 | return $next($request); |
|
| 61 | } |
||
| 63 |