| Conditions | 2 |
| Paths | 2 |
| Total Lines | 51 |
| Code Lines | 41 |
| 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 |
||
| 17 | public function run() |
||
| 18 | { |
||
| 19 | Model::unguard(); |
||
| 20 | $orang_tuas = (object) [ |
||
| 21 | (object) [ |
||
| 22 | 'nomor_un' => '123456789', |
||
| 23 | 'no_kk' => '12345', |
||
| 24 | 'alamat_ortu' => 'alamat 1', |
||
| 25 | 'nama_ayah' => 'nama ayah 1', |
||
| 26 | 'nama_ibu' => 'nama ibu 1', |
||
| 27 | 'kerja_ayah' => 'pekerjaan ayah 1', |
||
| 28 | 'pendidikan_ayah' => 'pendidikan ayah 1', |
||
| 29 | 'kerja_ibu' => 'pekerjaan ibu 1', |
||
| 30 | 'pendidikan_ibu' => 'pendidikan ibu 1', |
||
| 31 | 'no_telp' => '085212345', |
||
| 32 | 'user_id' => '1', |
||
| 33 | ], |
||
| 34 | (object) [ |
||
| 35 | 'nomor_un' => '123456730', |
||
| 36 | 'no_kk' => '123653', |
||
| 37 | 'alamat_ortu' => 'alamat 2', |
||
| 38 | 'nama_ayah' => 'nama ayah 2', |
||
| 39 | 'nama_ibu' => 'nama ibu 2', |
||
| 40 | 'kerja_ayah' => 'pekerjaan ayah 2', |
||
| 41 | 'pendidikan_ayah' => 'pendidikan ayah 2', |
||
| 42 | 'kerja_ibu' => 'pekerjaan ibu 2', |
||
| 43 | 'pendidikan_ibu' => 'pendidikan ibu 2', |
||
| 44 | 'no_telp' => '085222345', |
||
| 45 | 'user_id' => '2', |
||
| 46 | ] |
||
| 47 | ]; |
||
| 48 | |||
| 49 | foreach ($orang_tuas as $orang_tua) { |
||
| 50 | $model = OrangTua::create( |
||
| 51 | [ |
||
| 52 | 'nomor_un' => $orang_tua['nomor_un'], |
||
| 53 | 'no_kk' => $orang_tua['no_kk'], |
||
| 54 | 'alamat_ortu' => $orang_tua['alamat_ortu'], |
||
| 55 | 'nama_ayah' => $orang_tua['nama_ayah'], |
||
| 56 | 'nama_ibu' => $orang_tua['nama_ibu'], |
||
| 57 | 'kerja_ayah' => $orang_tua['kerja_ayah'], |
||
| 58 | 'pendidikan_ayah' => $orang_tua['pendidikan_ayah'], |
||
| 59 | 'kerja_ibu' => $orang_tua['kerja_ibu'], |
||
| 60 | 'pendidikan_ibu' => $orang_tua['pendidikan_ibu'], |
||
| 61 | 'no_telp' => $orang_tua['no_telp'], |
||
| 62 | 'user_id' => $orang_tua['user_id'], |
||
| 63 | ] |
||
| 64 | ); |
||
| 65 | $model->save(); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.