| Conditions | 15 | 
| Paths | 73 | 
| Total Lines | 51 | 
| Code Lines | 32 | 
| 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  | 
            ||
| 23 | public function handle($request, Closure $next)  | 
            ||
| 24 |     { | 
            ||
| 25 |         if (Auth::check()) { | 
            ||
| 26 | $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 |             if (App::environment() == 'local' && Config::get('app.force_admin')) { | 
            ||
| 31 |                 $user->setRole('admin'); | 
            ||
| 32 | $user->save();  | 
            ||
| 33 | }  | 
            ||
| 34 | |||
| 35 | // Ensure the user has a proper profile associated with it  | 
            ||
| 36 | // If no profile exists yet create one.  | 
            ||
| 37 | // Admins should be given an applicant and manager profile  | 
            ||
| 38 | if ($user->isApplicant() ||  | 
            ||
| 39 |                     $user->isAdmin()) { | 
            ||
| 40 | $applicantProfile = $user->applicant;  | 
            ||
| 41 |                 if ($applicantProfile === null) { | 
            ||
| 42 | $applicantProfile = new Applicant();  | 
            ||
| 43 | $applicantProfile->user_id = $user->id;  | 
            ||
| 44 | $applicantProfile->save();  | 
            ||
| 45 | $user->refresh();  | 
            ||
| 46 | }  | 
            ||
| 47 | }  | 
            ||
| 48 | if ($user->isManager() ||  | 
            ||
| 49 |                     $user->isAdmin()) { | 
            ||
| 50 | $managerProfile = $user->manager;  | 
            ||
| 51 |                 if ($managerProfile === null) { | 
            ||
| 52 | $managerProfile = new Manager();  | 
            ||
| 53 | $managerProfile->user_id = $user->id;  | 
            ||
| 54 |                     if ($user->isHrAdvisor() && $user->hr_advisor->department_id !== null) { | 
            ||
| 55 | $managerProfile->department_id = $user->hr_advisor->department_id;  | 
            ||
| 56 | }  | 
            ||
| 57 | $managerProfile->save();  | 
            ||
| 58 | $user->refresh();  | 
            ||
| 59 | }  | 
            ||
| 60 | }  | 
            ||
| 61 | if ($user->isHrAdvisor() ||  | 
            ||
| 62 |                     $user->isAdmin()) { | 
            ||
| 63 | $hrAdvisorProfile = $user->hr_advisor;  | 
            ||
| 64 |                 if ($hrAdvisorProfile === null) { | 
            ||
| 65 | $hrAdvisorProfile = new HrAdvisor();  | 
            ||
| 66 | $hrAdvisorProfile->user_id = $user->id;  | 
            ||
| 67 | $hrAdvisorProfile->save();  | 
            ||
| 68 | $user->refresh();  | 
            ||
| 69 | }  | 
            ||
| 70 | }  | 
            ||
| 71 | }  | 
            ||
| 72 | |||
| 73 | return $next($request);  | 
            ||
| 74 | }  | 
            ||
| 76 |