Conditions | 37 |
Paths | > 20000 |
Total Lines | 190 |
Lines | 112 |
Ratio | 58.95 % |
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 |
||
170 | public function update(Request $request, $id) |
||
171 | { |
||
172 | $directory = Directory::find($id); |
||
173 | if (!$directory) |
||
174 | { |
||
175 | throw new \UnexpectedValueException('the directory does not exist.', -10314); |
||
176 | } |
||
177 | |||
178 | $updValues = []; |
||
179 | |||
180 | $name = $request->input('name'); |
||
181 | View Code Duplication | if (isset($name)) |
|
182 | { |
||
183 | if (!$name) |
||
184 | { |
||
185 | throw new \UnexpectedValueException('the name can not be empty.', -10300); |
||
186 | } |
||
187 | $updValues['name'] = $name; |
||
188 | } |
||
189 | |||
190 | $configs = []; |
||
191 | |||
192 | $host = $request->input('host'); |
||
193 | View Code Duplication | if (isset($host)) |
|
194 | { |
||
195 | if (!$host) |
||
196 | { |
||
197 | throw new \UnexpectedValueException('the host can not be empty.', -10301); |
||
198 | } |
||
199 | $configs['host'] = $host; |
||
200 | } |
||
201 | |||
202 | $port = $request->input('port'); |
||
203 | View Code Duplication | if (isset($port)) |
|
204 | { |
||
205 | if (!$port) |
||
206 | { |
||
207 | throw new \UnexpectedValueException('the port can not be empty.', -10302); |
||
208 | } |
||
209 | $configs['port'] = intval($port); |
||
210 | } |
||
211 | |||
212 | $encryption = $request->input('encryption'); |
||
213 | if (isset($encryption)) |
||
214 | { |
||
215 | $configs['encryption'] = $encryption; |
||
216 | } |
||
217 | |||
218 | $admin_username = $request->input('admin_username'); |
||
219 | View Code Duplication | if (isset($admin_username)) |
|
220 | { |
||
221 | if (!$admin_username) |
||
222 | { |
||
223 | throw new \UnexpectedValueException('the username can not be empty.', -10303); |
||
224 | } |
||
225 | $configs['admin_username'] = $admin_username; |
||
226 | } |
||
227 | |||
228 | $admin_password = $request->input('admin_password'); |
||
229 | View Code Duplication | if (isset($admin_password)) |
|
230 | { |
||
231 | if (!$admin_password) |
||
232 | { |
||
233 | throw new \UnexpectedValueException('the user password can not be empty.', -10304); |
||
234 | } |
||
235 | $configs['admin_password'] = $admin_password; |
||
236 | } |
||
237 | |||
238 | $base_dn = $request->input('base_dn'); |
||
239 | View Code Duplication | if (isset($base_dn)) |
|
240 | { |
||
241 | if (!$base_dn) |
||
242 | { |
||
243 | throw new \UnexpectedValueException('the base_dn can not be empty.', -10305); |
||
244 | } |
||
245 | $configs['base_dn'] = $base_dn; |
||
246 | } |
||
247 | |||
248 | $additional_user_dn = $request->input('additional_user_dn'); |
||
249 | if (isset($additional_user_dn)) |
||
250 | { |
||
251 | $configs['additional_user_dn'] = $additional_user_dn; |
||
252 | } |
||
253 | |||
254 | $additional_group_dn = $request->input('additional_group_dn'); |
||
255 | if (isset($additional_group_dn)) |
||
256 | { |
||
257 | $configs['additional_group_dn'] = $additional_group_dn; |
||
258 | } |
||
259 | |||
260 | $user_object_class = $request->input('user_object_class'); |
||
261 | View Code Duplication | if (isset($user_object_class)) |
|
262 | { |
||
263 | if (!$user_object_class) |
||
264 | { |
||
265 | throw new \UnexpectedValueException('the user object class can not be empty.', -10306); |
||
266 | } |
||
267 | $configs['user_object_class'] = $user_object_class; |
||
268 | } |
||
269 | |||
270 | $user_object_filter = $request->input('user_object_filter'); |
||
271 | View Code Duplication | if (isset($user_object_filter)) |
|
272 | { |
||
273 | if (!$user_object_filter) |
||
274 | { |
||
275 | throw new \UnexpectedValueException('the user object filter can not be empty.', -10307); |
||
276 | } |
||
277 | $configs['user_object_filter'] = $user_object_filter; |
||
278 | } |
||
279 | |||
280 | $user_name_attr = $request->input('user_name_attr'); |
||
281 | View Code Duplication | if (isset($user_name_attr)) |
|
282 | { |
||
283 | if (!$user_name_attr) |
||
284 | { |
||
285 | throw new \UnexpectedValueException('the user name attributte can not be empty.', -10308); |
||
286 | } |
||
287 | $configs['user_name_attr'] = $user_name_attr; |
||
288 | } |
||
289 | |||
290 | $user_email_attr = $request->input('user_email_attr'); |
||
291 | View Code Duplication | if (isset($user_email_attr)) |
|
292 | { |
||
293 | if (!$user_email_attr) |
||
294 | { |
||
295 | throw new \UnexpectedValueException('the user email attributte can not be empty.', -10309); |
||
296 | } |
||
297 | $configs['user_email_attr'] = $user_email_attr; |
||
298 | } |
||
299 | |||
300 | $group_object_class = $request->input('group_object_class'); |
||
301 | View Code Duplication | if (isset($group_object_class)) |
|
302 | { |
||
303 | if (!$group_object_class) |
||
304 | { |
||
305 | throw new \UnexpectedValueException('the group object class can not be empty.', -10310); |
||
306 | } |
||
307 | $configs['group_object_class'] = $group_object_class; |
||
308 | } |
||
309 | |||
310 | $group_object_filter = $request->input('group_object_filter'); |
||
311 | View Code Duplication | if (isset($group_object_filter)) |
|
312 | { |
||
313 | if (!$group_object_filter) |
||
314 | { |
||
315 | throw new \UnexpectedValueException('the group object filter can not be empty.', -10311); |
||
316 | } |
||
317 | $configs['group_object_filter'] = $group_object_filter; |
||
318 | } |
||
319 | |||
320 | $group_name_attr = $request->input('group_name_attr'); |
||
321 | View Code Duplication | if (isset($group_name_attr)) |
|
322 | { |
||
323 | if (!$group_name_attr) |
||
324 | { |
||
325 | throw new \UnexpectedValueException('the group name attributte can not be empty.', -10312); |
||
326 | } |
||
327 | $configs['group_name_attr'] = $group_name_attr; |
||
328 | } |
||
329 | |||
330 | $group_membership_attr = $request->input('group_membership_attr'); |
||
331 | View Code Duplication | if (isset($group_membership_attr)) |
|
332 | { |
||
333 | if (!$group_membership_attr) |
||
334 | { |
||
335 | throw new \UnexpectedValueException('the group membership attributte can not be empty.', -10313); |
||
336 | } |
||
337 | $configs['group_membership_attr'] = $group_membership_attr; |
||
338 | } |
||
339 | |||
340 | if ($configs) |
||
341 | { |
||
342 | $updValues['configs'] = isset($directory->configs) ? array_merge($directory->configs ?: [], $configs) : $configs; |
||
343 | } |
||
344 | |||
345 | $invalid_flag = $request->input('invalid_flag'); |
||
346 | if (isset($invalid_flag)) |
||
347 | { |
||
348 | $updValues['invalid_flag'] = intval($invalid_flag); |
||
349 | } |
||
350 | |||
351 | $directory->fill($updValues)->save(); |
||
352 | |||
353 | //if (isset($invalid_flag)) |
||
354 | //{ |
||
355 | // EloquentUser::where('directory', $id)->update([ 'invalid_flag' => intval($invalid_flag) ]); |
||
356 | //} |
||
357 | |||
358 | return $this->show($id); |
||
359 | } |
||
360 | |||
461 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: