| Conditions | 31 |
| Paths | 1933 |
| Total Lines | 189 |
| Code Lines | 154 |
| Lines | 44 |
| Ratio | 23.28 % |
| 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 namespace Bantenprov\WilayahIndonesia\Http\Controllers; |
||
| 364 | public function kecamatansearch($provinsi,$kabupaten,$kecamatan) |
||
| 365 | { |
||
| 366 | $page = 10; |
||
| 367 | if($provinsi == 'provinsi'){ |
||
| 368 | $data = $this->indonesia->paginateProvinces($page); |
||
| 369 | }elseif($provinsi == 'kabupaten'){ |
||
| 370 | $data = $this->provinsi |
||
| 371 | ->select( |
||
| 372 | 'provinces.id as province_id', |
||
| 373 | 'provinces.name as province_name', |
||
| 374 | 'cities.id as city_id', |
||
| 375 | 'cities.name as city_name' |
||
| 376 | ) |
||
| 377 | ->leftjoin( |
||
| 378 | 'cities', |
||
| 379 | 'provinces.id','=','cities.province_id' |
||
| 380 | ) |
||
| 381 | ->paginate($page); |
||
| 382 | }elseif($provinsi == 'kecamatan'){ |
||
| 383 | $data = $this->provinsi |
||
| 384 | ->select( |
||
| 385 | 'provinces.id as province_id', |
||
| 386 | 'provinces.name as province_name', |
||
| 387 | 'cities.id as city_id', |
||
| 388 | 'cities.name as city_name', |
||
| 389 | 'districts.id as district_id', |
||
| 390 | 'districts.name as district_name' |
||
| 391 | ) |
||
| 392 | ->leftjoin( |
||
| 393 | 'cities', |
||
| 394 | 'provinces.id','=','cities.province_id' |
||
| 395 | ) |
||
| 396 | ->leftjoin( |
||
| 397 | 'districts', |
||
| 398 | 'cities.id','=','districts.city_id' |
||
| 399 | ) |
||
| 400 | ->paginate($page); |
||
| 401 | View Code Duplication | }elseif($provinsi == 'desa'){ |
|
| 402 | $data = $this->provinsi |
||
| 403 | ->select( |
||
| 404 | 'provinces.id as province_id', |
||
| 405 | 'provinces.name as province_name', |
||
| 406 | 'cities.id as city_id', |
||
| 407 | 'cities.name as city_name', |
||
| 408 | 'districts.id as district_id', |
||
| 409 | 'districts.name as district_name', |
||
| 410 | 'villages.id as village_id', |
||
| 411 | 'villages.name as village_name' |
||
| 412 | ) |
||
| 413 | ->leftjoin( |
||
| 414 | 'cities', |
||
| 415 | 'provinces.id','=','cities.province_id' |
||
| 416 | ) |
||
| 417 | ->leftjoin( |
||
| 418 | 'districts', |
||
| 419 | 'cities.id','=','districts.city_id' |
||
| 420 | ) |
||
| 421 | ->leftjoin( |
||
| 422 | 'villages', |
||
| 423 | 'districts.id','=','villages.district_id' |
||
| 424 | ) |
||
| 425 | ->paginate($page); |
||
| 426 | }else{ |
||
| 427 | $string = array('%20','+','-'); |
||
| 428 | foreach($string as $val){ |
||
| 429 | $provinsi = str_replace($val,' ',$provinsi); |
||
| 430 | } |
||
| 431 | $prov = $this->provinsi->where("name","=","$provinsi")->get(); |
||
| 432 | if($prov->count() > 0){ |
||
| 433 | $provinsi = $prov[0]->id; |
||
| 434 | foreach($string as $val){ |
||
| 435 | $kabupaten = str_replace($val,' ',$kabupaten); |
||
| 436 | } |
||
| 437 | $kab = $this->kabupaten->where("province_id","=","$provinsi")->where("name","=","$kabupaten")->get(); |
||
| 438 | if($kab->count() == 0){ |
||
| 439 | $kabupaten = 'kabupaten '.$kabupaten; |
||
| 440 | } |
||
| 441 | $kab1 = $this->kabupaten->where("province_id","=","$provinsi")->where("name","=","$kabupaten")->get(); |
||
| 442 | if($kab1->count() == 0){ |
||
| 443 | $kabupaten = 'kab '.$kabupaten; |
||
| 444 | } |
||
| 445 | $kab2 = $this->kabupaten->where("province_id","=","$provinsi")->where("name","=","$kabupaten")->get(); |
||
| 446 | if($kab2->count() == 0){ |
||
| 447 | $kabupaten = 'kab. '.$kabupaten; |
||
| 448 | } |
||
| 449 | $kab3 = $this->kabupaten->where("province_id","=","$provinsi")->where("name","=","$kabupaten")->get(); |
||
| 450 | if(($kab->count() > 0) || ($kab1->count() > 0) || ($kab2->count() > 0) || ($kab3->count() > 0)){ |
||
| 451 | View Code Duplication | if(isset($kab[0]->id)){ |
|
| 452 | $kabupaten = $kab[0]->id; |
||
| 453 | }elseif(isset($kab1[0]->id)){ |
||
| 454 | $kabupaten = $kab1[0]->id; |
||
| 455 | }elseif(isset($kab2[0]->id)){ |
||
| 456 | $kabupaten = $kab2[0]->id; |
||
| 457 | }elseif(isset($kab3[0]->id)){ |
||
| 458 | $kabupaten = $kab3[0]->id; |
||
| 459 | } |
||
| 460 | foreach($string as $val){ |
||
| 461 | $kecamatan = str_replace($val,' ',$kecamatan); |
||
| 462 | } |
||
| 463 | $kec = $this->kecamatan->where("city_id","=","$kabupaten")->where("name","=","$kecamatan")->get(); |
||
| 464 | if($kec->count() == 0){ |
||
| 465 | $kecamatan = 'kecamatan '.$kecamatan; |
||
| 466 | } |
||
| 467 | $kec1 = $this->kecamatan->where("city_id","=","$kabupaten")->where("name","=","$kecamatan")->get(); |
||
| 468 | if($kec1->count() == 0){ |
||
| 469 | $kecamatan = 'kec '.$kecamatan; |
||
| 470 | } |
||
| 471 | $kec2 = $this->kecamatan->where("city_id","=","$kabupaten")->where("name","=","$kecamatan")->get(); |
||
| 472 | if($kec2->count() == 0){ |
||
| 473 | $kecamatan = 'kec. '.$kecamatan; |
||
| 474 | } |
||
| 475 | $kec3 = $this->kecamatan->where("city_id","=","$kabupaten")->where("name","=","$kecamatan")->get(); |
||
| 476 | if(($kec->count() > 0) || ($kec1->count() > 0) || ($kec2->count() > 0) || ($kec3->count() > 0)){ |
||
| 477 | View Code Duplication | if(isset($kec[0]->id)){ |
|
| 478 | $kecamatan = $kec[0]->id; |
||
| 479 | }elseif(isset($kec1[0]->id)){ |
||
| 480 | $kecamatan = $kec1[0]->id; |
||
| 481 | }elseif(isset($kec2[0]->id)){ |
||
| 482 | $kecamatan = $kec2[0]->id; |
||
| 483 | }elseif(isset($kec3[0]->id)){ |
||
| 484 | $kecamatan = $kec3[0]->id; |
||
| 485 | } |
||
| 486 | $data = $this->provinsi |
||
| 487 | ->select( |
||
| 488 | 'provinces.id as province_id', |
||
| 489 | 'provinces.name as province_name', |
||
| 490 | 'cities.id as city_id', |
||
| 491 | 'cities.name as city_name', |
||
| 492 | 'districts.id as district_id', |
||
| 493 | 'districts.name as district_name', |
||
| 494 | 'villages.id as village_id', |
||
| 495 | 'villages.name as village_name' |
||
| 496 | ) |
||
| 497 | ->leftjoin( |
||
| 498 | 'cities', |
||
| 499 | 'provinces.id','=','cities.province_id' |
||
| 500 | ) |
||
| 501 | ->leftjoin( |
||
| 502 | 'districts', |
||
| 503 | 'cities.id','=','districts.city_id' |
||
| 504 | ) |
||
| 505 | ->leftjoin( |
||
| 506 | 'villages', |
||
| 507 | 'districts.id','=','villages.district_id' |
||
| 508 | ) |
||
| 509 | ->where('villages.district_id','=',$kecamatan) |
||
| 510 | ->paginate($page); |
||
| 511 | }else{ |
||
| 512 | $data = $this->provinsi |
||
| 513 | ->select( |
||
| 514 | 'provinces.id as province_id', |
||
| 515 | 'provinces.name as province_name', |
||
| 516 | 'cities.id as city_id', |
||
| 517 | 'cities.name as city_name', |
||
| 518 | 'districts.id as district_id', |
||
| 519 | 'districts.name as district_name' |
||
| 520 | ) |
||
| 521 | ->leftjoin( |
||
| 522 | 'cities', |
||
| 523 | 'provinces.id','=','cities.province_id' |
||
| 524 | ) |
||
| 525 | ->leftjoin( |
||
| 526 | 'districts', |
||
| 527 | 'cities.id','=','districts.city_id' |
||
| 528 | ) |
||
| 529 | ->where('districts.city_id','=',$kabupaten) |
||
| 530 | ->paginate($page); |
||
| 531 | } |
||
| 532 | }else{ |
||
| 533 | $data = $this->provinsi |
||
| 534 | ->select( |
||
| 535 | 'provinces.id as province_id', |
||
| 536 | 'provinces.name as province_name', |
||
| 537 | 'cities.id as city_id', |
||
| 538 | 'cities.name as city_name' |
||
| 539 | ) |
||
| 540 | ->leftjoin( |
||
| 541 | 'cities', |
||
| 542 | 'provinces.id','=','cities.province_id' |
||
| 543 | ) |
||
| 544 | ->where('cities.province_id','=',$provinsi) |
||
| 545 | ->paginate($page); |
||
| 546 | } |
||
| 547 | }else{ |
||
| 548 | $data = $this->indonesia->paginateProvinces($page); |
||
| 549 | } |
||
| 550 | } |
||
| 551 | return Response::make(json_encode($data, JSON_PRETTY_PRINT))->header('Content-Type', "application/json"); |
||
| 552 | } |
||
| 553 | //END DATA KECAMATAN |
||
| 604 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: