Conditions | 12 |
Paths | 54 |
Total Lines | 129 |
Code Lines | 103 |
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 |
||
321 | public function update(Request $request, $version='', $id) |
||
322 | { |
||
323 | $result = EpormasCounter::whereNull('deleted_at') |
||
324 | ->with('getCity') |
||
325 | ->with('getCategory') |
||
326 | ->find($id); |
||
327 | |||
328 | $rules = [ |
||
329 | 'count' => 'required|numeric', |
||
330 | 'city_id' => 'required|numeric', |
||
331 | 'category_id' => 'required|numeric', |
||
332 | 'tanggal' => 'required|date', |
||
333 | ]; |
||
334 | |||
335 | $validator = Validator::make($request->all(), $rules); |
||
336 | if ($validator->fails()) { |
||
337 | return response()->json([ |
||
338 | 'title' => 'Error', |
||
339 | 'type' => 'error', |
||
340 | 'message' => $validator->errors()->all() |
||
341 | ]); |
||
342 | } |
||
343 | |||
344 | $format = date('Y-m-d', strtotime(str_replace(' ','-',$request->tanggal))); |
||
345 | if($result->city_id != $request->city_id || $result->category_id != $request->category_id){ |
||
346 | $resultcek = EpormasCounter::whereNull('deleted_at') |
||
347 | ->where('tanggal','like','%'.$format.'%') |
||
348 | ->where('category_id',$request->category_id) |
||
349 | ->where('city_id',$request->city_id) |
||
350 | ->groupBy('tahun','bulan','category_id','city_id') |
||
351 | ->orderBy('bulan') |
||
352 | ->count(); |
||
353 | if($resultcek > 0){ |
||
354 | return response()->json([ |
||
355 | 'title' => 'Error', |
||
356 | 'type' => 'error', |
||
357 | 'message' => 'Data has already been taken.' |
||
358 | ]); |
||
359 | } |
||
360 | } |
||
361 | |||
362 | $date = explode("-",$format); |
||
363 | $dates = date('Y-m-d', strtotime($result->tanggal)); |
||
364 | if($dates != $format){ |
||
365 | $resultcek = EpormasCounter::whereNull('deleted_at') |
||
366 | ->where('category_id',$request->category_id) |
||
367 | ->where('city_id',$request->city_id) |
||
368 | ->where('tanggal','like','%'.$format.'%') |
||
369 | ->groupBy('tahun','bulan','category_id','city_id') |
||
370 | ->orderBy('bulan') |
||
371 | ->count(); |
||
372 | if($resultcek > 0){ |
||
373 | return response()->json([ |
||
374 | 'title' => 'Error', |
||
375 | 'type' => 'error', |
||
376 | 'message' => 'Data has already been taken.' |
||
377 | ]); |
||
378 | } |
||
379 | |||
380 | $data = EpormasCounter::whereNull('deleted_at') |
||
381 | ->where('tahun', $date[0]) |
||
382 | ->where('bulan', $date[1]) |
||
383 | ->where('category_id',$request->category_id) |
||
384 | ->where('city_id',$request->city_id) |
||
385 | ->groupBy('tahun','bulan','category_id','city_id') |
||
386 | ->orderBy('bulan') |
||
387 | ->count(); |
||
388 | if($data > 0){ |
||
389 | return response()->json([ |
||
390 | 'title' => 'Error', |
||
391 | 'type' => 'error', |
||
392 | 'message' => 'Data has already been taken.' |
||
393 | ]); |
||
394 | } |
||
395 | } |
||
396 | |||
397 | $path = \Request::path(); |
||
398 | $explode = explode('/', $path); |
||
399 | |||
400 | $from = $result->via; |
||
401 | $user_id = $result->user_id; |
||
402 | if(in_array('api',$explode)){ |
||
403 | $from = 'api'; |
||
404 | $user_id = $request->user_id; |
||
405 | } |
||
406 | |||
407 | $via = $from; |
||
408 | if($version != '' && $version != 'update'){ |
||
409 | $via .= '-'.$version; |
||
410 | } |
||
411 | |||
412 | try { |
||
413 | $error = false; |
||
414 | $statusCode = 200; |
||
415 | $title = 'Success'; |
||
416 | $type = 'success'; |
||
417 | $message = 'Data updated successfully'; |
||
418 | $result->update([ |
||
419 | 'count' => $request->count, |
||
420 | 'category_id' => $request->category_id, |
||
421 | 'city_id' => $request->city_id, |
||
422 | 'tahun' => $date[0], |
||
423 | 'bulan' => $date[1], |
||
424 | 'tanggal' => $format, |
||
425 | 'user_id' => $user_id, |
||
426 | 'via' => $via |
||
427 | ]); |
||
428 | return Response::json(array( |
||
429 | 'error' => $error, |
||
430 | 'status' => $statusCode, |
||
431 | 'title' => $title, |
||
432 | 'type' => $type, |
||
433 | 'message' => $message, |
||
434 | 'result' => $result |
||
435 | )); |
||
436 | } catch (Exception $e) { |
||
437 | $error = true; |
||
438 | $statusCode = 404; |
||
439 | $title = 'Error'; |
||
440 | $type = 'error'; |
||
441 | $message = 'Error'; |
||
442 | $result = 'Not Found'; |
||
443 | return Response::json(array( |
||
444 | 'error' => $error, |
||
445 | 'status' => $statusCode, |
||
446 | 'title' => $title, |
||
447 | 'type' => $type, |
||
448 | 'message' => $message, |
||
449 | 'result' => $result |
||
450 | )); |
||
495 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths