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 | 25 | public function handle($request, Closure $next) |
|
1 ignored issue
–
show
|
|||
24 | { |
||
25 | 25 | if (Auth::check()) { |
|
26 | 16 | $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 | 16 | 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 | 16 | if ($user->hasRole('applicant') || |
|
41 | 16 | $user->hasRole('admin') ) { |
|
42 | 11 | $applicantProfile = $user->applicant; |
|
43 | 11 | if ($applicantProfile === null) { |
|
44 | 2 | $applicantProfile = new Applicant(); |
|
45 | 2 | $applicantProfile->user_id = $user->id; |
|
46 | 2 | $applicantProfile->save(); |
|
47 | } |
||
48 | } |
||
49 | 16 | if ($user->hasRole('manager') || |
|
50 | 16 | $user->hasRole('admin')) { |
|
51 | 6 | $managerProfile = $user->manager; |
|
52 | 6 | if ($managerProfile === null) { |
|
53 | 1 | $managerProfile = new Manager(); |
|
54 | 1 | $managerProfile->user_id = $user->id; |
|
55 | 1 | $managerProfile->save(); |
|
56 | } |
||
57 | } |
||
58 | } |
||
59 | |||
60 | 25 | return $next($request); |
|
61 | } |
||
63 |