| Conditions | 23 |
| Paths | 8 |
| Total Lines | 88 |
| Code Lines | 66 |
| 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 |
||
| 105 | public function getUserOrg(Request $request) |
||
| 106 | { |
||
| 107 | if($request->user()->super_admin){ |
||
| 108 | $data = [ |
||
| 109 | [ |
||
| 110 | "orgId" => 2, |
||
| 111 | "userId" => $request->user()->id, |
||
| 112 | "role" => 'Admin', |
||
| 113 | "name" => 'Schools', |
||
| 114 | "email" => $request->user()->username, |
||
| 115 | "login" => 'Schools', |
||
| 116 | ], |
||
| 117 | [ |
||
| 118 | "orgId" => 4, |
||
| 119 | "userId" => $request->user()->id, |
||
| 120 | "role" => 'Admin', |
||
| 121 | "name" => 'Zones', |
||
| 122 | "email" => $request->user()->username, |
||
| 123 | "login" => 'Zones', |
||
| 124 | ], |
||
| 125 | [ |
||
| 126 | "orgId" => 5, |
||
| 127 | "userId" => $request->user()->id, |
||
| 128 | "role" => 'Admin', |
||
| 129 | "name" => 'Provinces', |
||
| 130 | "email" => $request->user()->username, |
||
| 131 | "login" => 'Provinces', |
||
| 132 | ] |
||
| 133 | ]; |
||
| 134 | }elseif ($request->user() && (!($request->user()->principal->isEmpty())) && !is_null($request->user()->principal) && ($request->user()->principal[0]->roles->code == 'PRINCIPAL')) { |
||
| 135 | $data = $this->checkOrg($request); |
||
| 136 | if (empty($data) || ( (!empty($data['orgId']) && $data['orgId'] !== 2))) { |
||
| 137 | $request['data'] = $data; |
||
| 138 | $data['user'] = $data; |
||
| 139 | $data['orgId'] = 2; |
||
| 140 | $this->updateUserOrg($request, $data); |
||
| 141 | $this->removeUserMainOrg($data); |
||
| 142 | } |
||
| 143 | $data = [ |
||
| 144 | [ |
||
| 145 | "orgId" => 2, |
||
| 146 | "userId" => $request->user()->id, |
||
| 147 | "role" => 'Viewer', |
||
| 148 | "name" => 'Schools', |
||
| 149 | "email" => $request->user()->username, |
||
| 150 | "login" => 'Schools', |
||
| 151 | ] |
||
| 152 | ]; |
||
| 153 | } elseif ($request->user() && (!($request->user()->zonal_cordinator->isEmpty())) && !is_null($request->user()->zonal_cordinator) && ($request->user()->zonal_cordinator[0]->roles->code == 'ZONAL_COORDINATOR')) { |
||
| 154 | $data = $this->checkOrg($request); |
||
| 155 | if (empty($data) || ((!empty($data['orgId']) && $data['orgId'] !== 4))) { |
||
| 156 | $request['data'] = $data; |
||
| 157 | $data['user'] = $data; |
||
| 158 | $data['orgId'] = 4; |
||
| 159 | $this->updateUserOrg($request, $data); |
||
| 160 | $this->removeUserMainOrg($data); |
||
| 161 | } |
||
| 162 | $data = [ |
||
| 163 | [ |
||
| 164 | "orgId" => 4, |
||
| 165 | "userId" => $request->user()->id, |
||
| 166 | "role" => 'Viewer', |
||
| 167 | "name" => 'Zones', |
||
| 168 | "email" => $request->user()->username, |
||
| 169 | "login" => 'Zones', |
||
| 170 | ] |
||
| 171 | ]; |
||
| 172 | } elseif ($request->user() && (!($request->user()->provincial_cordinator->isEmpty())) && !is_null($request->user()->provincial_cordinator) && ($request->user()->provincial_cordinator[0]->roles->code == 'PROVINCIAL_COORDINATOR')) { |
||
| 173 | $data = $this->checkOrg($request); |
||
| 174 | if (empty($data) || ((!empty($data['orgId']) && $data['orgId'] !== 5))) { |
||
| 175 | $request['data'] = $data; |
||
| 176 | $data['user'] = $data; |
||
| 177 | $data['orgId'] = 5; |
||
| 178 | $this->updateUserOrg($request, $data); |
||
| 179 | $this->removeUserMainOrg($data); |
||
| 180 | } |
||
| 181 | $data = [ |
||
| 182 | [ |
||
| 183 | "orgId" => 5, |
||
| 184 | "userId" => $request->user()->id, |
||
| 185 | "role" => 'Viewer', |
||
| 186 | "name" => 'Provinces', |
||
| 187 | "email" => $request->user()->username, |
||
| 188 | "login" => 'Provinces', |
||
| 189 | ] |
||
| 190 | ]; |
||
| 191 | } |
||
| 192 | return $data; |
||
| 193 | } |
||
| 195 |