| Conditions | 14 |
| Paths | 56 |
| Total Lines | 59 |
| Code Lines | 30 |
| 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 |
||
| 88 | public function retrieveByCredentials(array $credentials) { |
||
| 89 | if (empty($credentials)) { |
||
| 90 | return; |
||
| 91 | } |
||
| 92 | if (isset($credentials['iss']) && isset($credentials['sub'])) { |
||
| 93 | // First we will try to find a user that matches the openid issuer |
||
| 94 | // and sub code. |
||
| 95 | |||
| 96 | $model = $this->createModel(); |
||
| 97 | |||
| 98 | $user = $model->findByOidcSub($credentials['iss'], $credentials['sub']); |
||
| 99 | |||
| 100 | // If no user was found, use the provided credentials to create a |
||
| 101 | // new user |
||
| 102 | if ($user === null) { |
||
| 103 | |||
| 104 | $user = $this->createUserFromCredentials($credentials); |
||
| 105 | if ($user) { |
||
| 106 | //If a user was created successfully, save it to database |
||
| 107 | $user->save(); |
||
| 108 | } |
||
| 109 | |||
| 110 | } |
||
| 111 | |||
| 112 | //If running in a local environment, and FORCE_ADMIN is true, |
||
| 113 | //automatically set any logged in user to (temporarilly) be an admin |
||
| 114 | if (App::environment() == 'local' && Config::get('app.force_admin')) { |
||
| 115 | $adminRole = UserRole::where('name', 'admin')->firstOrFail(); |
||
| 116 | $user->user_role_id = $adminRole->id; |
||
| 117 | // $user->user_role = $adminRole; |
||
| 118 | $user->save(); |
||
| 119 | } |
||
| 120 | |||
| 121 | //Ensure the user has a proper profile associated with it |
||
| 122 | //If now profile exists yet create one. |
||
| 123 | //Admins should be givven an applicant and manager profile |
||
| 124 | if ($user->user_role->name == 'applicant' || |
||
| 125 | $user->user_role->name == 'admin') { |
||
| 126 | $applicantProfile = Applicant::where(['user_id' => $user->id])->first(); |
||
| 127 | if (!$applicantProfile) { |
||
| 128 | $applicantProfile = new Applicant(); |
||
| 129 | $applicantProfile->user_id = $user->id; |
||
| 130 | $applicantProfile->save(); |
||
| 131 | } |
||
| 132 | |||
| 133 | } |
||
| 134 | if ($user->user_role->name == 'manager' || |
||
| 135 | $user->user_role->name == 'admin') { |
||
| 136 | $managerProfile = Manager::where(['user_id' => $user->id])->first(); |
||
| 137 | if (!$managerProfile) { |
||
| 138 | $managerProfile = new Manager(); |
||
| 139 | $managerProfile->user_id = $user->id; |
||
| 140 | $managerProfile->save(); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | return $user; |
||
| 145 | } else { |
||
| 146 | return; |
||
| 147 | } |
||
| 217 |