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