| Conditions | 22 |
| Paths | 7 |
| Total Lines | 58 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 105 | public function getUserOrg(Request $request) |
||
| 106 | { |
||
| 107 | if ($request->user() && (!($request->user()->principal->isEmpty())) && !is_null($request->user()->principal) && ($request->user()->principal[0]->roles->code == 'PRINCIPAL')) { |
||
| 108 | $data = $this->checkOrg($request); |
||
| 109 | if (empty($data) || ( (!empty($data['orgId']) && $data['orgId'] !== 2))) { |
||
| 110 | $request['data'] = $data; |
||
| 111 | $data['user'] = $data; |
||
| 112 | $data['orgId'] = 2; |
||
| 113 | $this->updateUserOrg($request, $data); |
||
| 114 | } |
||
| 115 | $data = [ |
||
| 116 | [ |
||
| 117 | "orgId" => 2, |
||
| 118 | "userId" => $request->user()->id, |
||
| 119 | "role" => 'Viewer', |
||
| 120 | "name" => 'schools', |
||
| 121 | "email" => $request->user()->username, |
||
| 122 | "login" => 'schools', |
||
| 123 | ] |
||
| 124 | ]; |
||
| 125 | } elseif ($request->user() && (!($request->user()->zonal_cordinator->isEmpty())) && !is_null($request->user()->zonal_cordinator) && ($request->user()->zonal_cordinator[0]->roles->code == 'ZONAL_COORDINATOR')) { |
||
| 126 | $data = $this->checkOrg($request); |
||
| 127 | if (empty($data) || ((!empty($data['orgId']) && $data['orgId'] !== 3))) { |
||
| 128 | $request['data'] = $data; |
||
| 129 | $data['user'] = $data; |
||
| 130 | $data['orgId'] = 3; |
||
| 131 | $this->updateUserOrg($request, $data); |
||
| 132 | } |
||
| 133 | $data = [ |
||
| 134 | [ |
||
| 135 | "orgId" => 3, |
||
| 136 | "userId" => $request->user()->id, |
||
| 137 | "role" => 'Viewer', |
||
| 138 | "name" => 'zone', |
||
| 139 | "email" => $request->user()->username, |
||
| 140 | "login" => 'zone', |
||
| 141 | ] |
||
| 142 | ]; |
||
| 143 | } elseif ($request->user() && (!($request->user()->provincial_cordinator->isEmpty())) && !is_null($request->user()->provincial_cordinator) && ($request->user()->provincial_cordinator[0]->roles->code == 'PROVINCIAL_COORDINATOR')) { |
||
| 144 | $data = $this->checkOrg($request); |
||
| 145 | if (empty($data) || ((!empty($data['orgId']) && $data['orgId'] !== 4))) { |
||
| 146 | $request['data'] = $data; |
||
| 147 | $data['user'] = $data; |
||
| 148 | $data['orgId'] = 4; |
||
| 149 | $this->updateUserOrg($request, $data); |
||
| 150 | } |
||
| 151 | $data = [ |
||
| 152 | [ |
||
| 153 | "orgId" => 4, |
||
| 154 | "userId" => $request->user()->id, |
||
| 155 | "role" => 'Viewer', |
||
| 156 | "name" => 'province', |
||
| 157 | "email" => $request->user()->username, |
||
| 158 | "login" => 'province', |
||
| 159 | ] |
||
| 160 | ]; |
||
| 161 | } |
||
| 162 | return $data; |
||
| 163 | } |
||
| 165 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.