| Conditions | 23 |
| Paths | 8 |
| Total Lines | 88 |
| Code Lines | 66 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 4 | Features | 2 |
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 |
||
| 132 | public function getUserOrg(Request $request) |
||
| 133 | { |
||
| 134 | if ($request->user()->super_admin) { |
||
| 135 | $data = [ |
||
| 136 | [ |
||
| 137 | "orgId" => 2, |
||
| 138 | "userId" => $request->user()->id, |
||
| 139 | "role" => 'Admin', |
||
| 140 | "name" => 'Schools', |
||
| 141 | "email" => $request->user()->username, |
||
| 142 | "login" => 'Schools', |
||
| 143 | ], |
||
| 144 | [ |
||
| 145 | "orgId" => 4, |
||
| 146 | "userId" => $request->user()->id, |
||
| 147 | "role" => 'Admin', |
||
| 148 | "name" => 'Zones', |
||
| 149 | "email" => $request->user()->username, |
||
| 150 | "login" => 'Zones', |
||
| 151 | ], |
||
| 152 | [ |
||
| 153 | "orgId" => 5, |
||
| 154 | "userId" => $request->user()->id, |
||
| 155 | "role" => 'Admin', |
||
| 156 | "name" => 'Provinces', |
||
| 157 | "email" => $request->user()->username, |
||
| 158 | "login" => 'Provinces', |
||
| 159 | ] |
||
| 160 | ]; |
||
| 161 | } elseif ($request->user() && (!($request->user()->principal->isEmpty())) && !is_null($request->user()->principal) && ($request->user()->principal[0]->roles->code == 'PRINCIPAL')) { |
||
| 162 | $data = $this->checkOrg($request); |
||
| 163 | if (empty($data) || ((!empty($data['orgId']) && $data['orgId'] !== 2))) { |
||
| 164 | $request['data'] = $data; |
||
| 165 | $data['user'] = $data; |
||
| 166 | $data['orgId'] = 2; |
||
| 167 | $this->updateUserOrg($request, $data); |
||
| 168 | $this->removeUserMainOrg($data); |
||
| 169 | } |
||
| 170 | $data = [ |
||
| 171 | [ |
||
| 172 | "orgId" => 2, |
||
| 173 | "userId" => $request->user()->id, |
||
| 174 | "role" => 'Viewer', |
||
| 175 | "name" => 'Schools', |
||
| 176 | "email" => $request->user()->username, |
||
| 177 | "login" => 'Schools', |
||
| 178 | ] |
||
| 179 | ]; |
||
| 180 | } elseif ($request->user() && (!($request->user()->zonal_cordinator->isEmpty())) && !is_null($request->user()->zonal_cordinator) && ($request->user()->zonal_cordinator[0]->roles->code == 'ZONAL_COORDINATOR')) { |
||
| 181 | $data = $this->checkOrg($request); |
||
| 182 | if (empty($data) || ((!empty($data['orgId']) && $data['orgId'] !== 4))) { |
||
| 183 | $request['data'] = $data; |
||
| 184 | $data['user'] = $data; |
||
| 185 | $data['orgId'] = 4; |
||
| 186 | $this->updateUserOrg($request, $data); |
||
| 187 | $this->removeUserMainOrg($data); |
||
| 188 | } |
||
| 189 | $data = [ |
||
| 190 | [ |
||
| 191 | "orgId" => 4, |
||
| 192 | "userId" => $request->user()->id, |
||
| 193 | "role" => 'Viewer', |
||
| 194 | "name" => 'Zones', |
||
| 195 | "email" => $request->user()->username, |
||
| 196 | "login" => 'Zones', |
||
| 197 | ] |
||
| 198 | ]; |
||
| 199 | } elseif ($request->user() && (!($request->user()->provincial_cordinator->isEmpty())) && !is_null($request->user()->provincial_cordinator) && ($request->user()->provincial_cordinator[0]->roles->code == 'PROVINCIAL_COORDINATOR')) { |
||
| 200 | $data = $this->checkOrg($request); |
||
| 201 | if (empty($data) || ((!empty($data['orgId']) && $data['orgId'] !== 5))) { |
||
| 202 | $request['data'] = $data; |
||
| 203 | $data['user'] = $data; |
||
| 204 | $data['orgId'] = 5; |
||
| 205 | $this->updateUserOrg($request, $data); |
||
| 206 | $this->removeUserMainOrg($data); |
||
| 207 | } |
||
| 208 | $data = [ |
||
| 209 | [ |
||
| 210 | "orgId" => 5, |
||
| 211 | "userId" => $request->user()->id, |
||
| 212 | "role" => 'Viewer', |
||
| 213 | "name" => 'Provinces', |
||
| 214 | "email" => $request->user()->username, |
||
| 215 | "login" => 'Provinces', |
||
| 216 | ] |
||
| 217 | ]; |
||
| 218 | } |
||
| 219 | return $data; |
||
| 220 | } |
||
| 222 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.