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