Conditions | 11 |
Paths | 22 |
Total Lines | 113 |
Code Lines | 88 |
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 |
||
272 | public function update(Request $request, $version='', $id) |
||
273 | { |
||
274 | $result = EpormasCounter::whereNull('deleted_at') |
||
275 | ->with('getCity') |
||
276 | ->with('getCategory') |
||
277 | ->find($id); |
||
278 | |||
279 | $rules = [ |
||
280 | 'count' => 'required|numeric', |
||
281 | 'city_id' => 'required|numeric', |
||
282 | 'category_id' => 'required|numeric', |
||
283 | 'tanggal' => 'required|date', |
||
284 | ]; |
||
285 | |||
286 | $validator = Validator::make($request->all(), $rules); |
||
287 | if ($validator->fails()) { |
||
288 | return Response::json(array( |
||
289 | 'title' => 'Error', |
||
290 | 'type' => 'error', |
||
291 | 'message' => $validator->errors()->all() |
||
292 | )); |
||
293 | } |
||
294 | |||
295 | $format = date('Y-m-d', strtotime(str_replace(' ','-',$request->tanggal))); |
||
296 | if($result->city_id != $request->city_id || $result->category_id != $request->category_id){ |
||
297 | $resultcek = EpormasCounter::whereNull('deleted_at') |
||
298 | ->where('tanggal','like','%'.$format.'%') |
||
299 | ->where('category_id',$request->category_id) |
||
300 | ->where('city_id',$request->city_id) |
||
301 | ->groupBy('tahun','bulan','category_id','city_id') |
||
302 | ->orderBy('bulan') |
||
303 | ->count(); |
||
304 | if($resultcek > 0){ |
||
305 | return Response::json(array( |
||
306 | 'title' => 'Error', |
||
307 | 'type' => 'error', |
||
308 | 'message' => 'Data has already been taken.' |
||
309 | )); |
||
310 | } |
||
311 | } |
||
312 | |||
313 | $date = explode("-",$format); |
||
314 | $dates = date('Y-m-d', strtotime($result->tanggal)); |
||
315 | if($dates != $format){ |
||
316 | $resultcek = EpormasCounter::whereNull('deleted_at') |
||
317 | ->where('category_id',$request->category_id) |
||
318 | ->where('city_id',$request->city_id) |
||
319 | ->where('tanggal','like','%'.$format.'%') |
||
320 | ->groupBy('tahun','bulan','category_id','city_id') |
||
321 | ->orderBy('bulan') |
||
322 | ->count(); |
||
323 | if($resultcek > 0){ |
||
324 | return Response::json(array( |
||
325 | 'title' => 'Error', |
||
326 | 'type' => 'error', |
||
327 | 'message' => 'Data has already been taken.' |
||
328 | )); |
||
329 | } |
||
330 | |||
331 | $data = EpormasCounter::whereNull('deleted_at') |
||
332 | ->where('tahun', $date[0]) |
||
333 | ->where('bulan', $date[1]) |
||
334 | ->where('category_id',$request->category_id) |
||
335 | ->where('city_id',$request->city_id) |
||
336 | ->groupBy('tahun','bulan','category_id','city_id') |
||
337 | ->orderBy('bulan') |
||
338 | ->count(); |
||
339 | if($data > 0){ |
||
340 | return Response::json(array( |
||
341 | 'title' => 'Error', |
||
342 | 'type' => 'error', |
||
343 | 'message' => 'Data has already been taken.' |
||
344 | )); |
||
345 | } |
||
346 | } |
||
347 | |||
348 | $path = \Request::path(); |
||
349 | $explode = explode('/', $path); |
||
350 | |||
351 | $from = $result->via; |
||
352 | $user_id = $result->user_id; |
||
353 | if(in_array('api',$explode)){ |
||
354 | $from = 'api'; |
||
355 | $user_id = $request->user_id; |
||
356 | } |
||
357 | |||
358 | $via = $from; |
||
359 | if($version != '' && $version != 'update'){ |
||
360 | $via .= '-'.$version; |
||
361 | } |
||
362 | |||
363 | $error = false; |
||
364 | $statusCode = 200; |
||
365 | $title = 'Success'; |
||
366 | $type = 'success'; |
||
367 | $message = 'Data updated successfully'; |
||
368 | $result->update([ |
||
369 | 'count' => $request->count, |
||
370 | 'category_id' => $request->category_id, |
||
371 | 'city_id' => $request->city_id, |
||
372 | 'tahun' => $date[0], |
||
373 | 'bulan' => $date[1], |
||
374 | 'tanggal' => $format, |
||
375 | 'user_id' => $user_id, |
||
376 | 'via' => $via |
||
377 | ]); |
||
378 | return Response::json(array( |
||
379 | 'error' => $error, |
||
380 | 'status' => $statusCode, |
||
381 | 'title' => $title, |
||
382 | 'type' => $type, |
||
383 | 'message' => $message, |
||
384 | 'result' => $result |
||
385 | )); |
||
414 |
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