| Conditions | 8 |
| Paths | 7 |
| Total Lines | 73 |
| Code Lines | 56 |
| 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 |
||
| 215 | public function update(Request $request, $id) |
||
| 216 | { |
||
| 217 | $response = array(); |
||
| 218 | $message = array(); |
||
| 219 | $orang_tua = $this->orang_tua->findOrFail($id); |
||
| 220 | |||
| 221 | $validator = Validator::make($request->all(), [ |
||
| 222 | 'user_id' => 'required|unique:orangtuas,user_id,'.$id, |
||
| 223 | 'nomor_un' => 'required |unique:orangtuas,nomor_un,'.$id, |
||
| 224 | 'no_kk' => 'required|unique:orangtuas,no_kk,'.$id, |
||
| 225 | 'no_telp' => 'required|unique:orangtuas,no_telp,'.$id, |
||
| 226 | 'nama_ayah' => 'required', |
||
| 227 | 'nama_ibu' => 'required', |
||
| 228 | 'pendidikan_ayah' => 'required', |
||
| 229 | 'kerja_ayah' => 'required', |
||
| 230 | 'pendidikan_ibu' => 'required', |
||
| 231 | 'kerja_ibu' => 'required', |
||
| 232 | 'alamat_ortu' => 'required', |
||
| 233 | ]); |
||
| 234 | |||
| 235 | if ($validator->fails()) { |
||
| 236 | |||
| 237 | foreach($validator->messages()->getMessages() as $key => $error){ |
||
| 238 | foreach($error AS $error_get) { |
||
| 239 | array_push($message, $error_get); |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | $check_user = $this->orang_tua->where('id','!=', $id)->where('user_id', $request->user_id); |
||
| 244 | $check_nomor_un = $this->orang_tua->where('id','!=', $id)->where('nomor_un', $request->nomor_un); |
||
| 245 | $check_no_kk = $this->orang_tua->where('id','!=', $id)->where('no_kk', $request->no_kk); |
||
| 246 | $check_no_telp = $this->orang_tua->where('id','!=', $id)->where('no_telp', $request->no_telp); |
||
| 247 | |||
| 248 | if($check_user->count() > 0 || $check_nomor_un->count() > 0 || $check_no_kk->count() > 0 || $check_no_telp->count() > 0){ |
||
| 249 | $response['message'] = implode("\n",$message); |
||
| 250 | } else { |
||
| 251 | $orang_tua->user_id = $request->input('user_id'); |
||
| 252 | $orang_tua->nomor_un = $request->input('nomor_un'); |
||
| 253 | $orang_tua->no_kk = $request->input('no_kk'); |
||
| 254 | $orang_tua->no_telp = $request->input('no_telp'); |
||
| 255 | $orang_tua->nama_ayah = $request->input('nama_ayah'); |
||
| 256 | $orang_tua->nama_ibu = $request->input('nama_ibu'); |
||
| 257 | $orang_tua->pendidikan_ayah = $request->input('pendidikan_ayah'); |
||
| 258 | $orang_tua->kerja_ayah = $request->input('kerja_ayah'); |
||
| 259 | $orang_tua->pendidikan_ibu = $request->input('pendidikan_ibu'); |
||
| 260 | $orang_tua->kerja_ibu = $request->input('kerja_ibu'); |
||
| 261 | $orang_tua->alamat_ortu = $request->input('alamat_ortu'); |
||
| 262 | $orang_tua->save(); |
||
| 263 | |||
| 264 | $response['message'] = 'success'; |
||
| 265 | |||
| 266 | } |
||
| 267 | } else { |
||
| 268 | $orang_tua->user_id = $request->input('user_id'); |
||
| 269 | $orang_tua->nomor_un = $request->input('nomor_un'); |
||
| 270 | $orang_tua->no_kk = $request->input('no_kk'); |
||
| 271 | $orang_tua->no_telp = $request->input('no_telp'); |
||
| 272 | $orang_tua->nama_ayah = $request->input('nama_ayah'); |
||
| 273 | $orang_tua->nama_ibu = $request->input('nama_ibu'); |
||
| 274 | $orang_tua->pendidikan_ayah = $request->input('pendidikan_ayah'); |
||
| 275 | $orang_tua->kerja_ayah = $request->input('kerja_ayah'); |
||
| 276 | $orang_tua->pendidikan_ibu = $request->input('pendidikan_ibu'); |
||
| 277 | $orang_tua->kerja_ibu = $request->input('kerja_ibu'); |
||
| 278 | $orang_tua->alamat_ortu = $request->input('alamat_ortu'); |
||
| 279 | $orang_tua->save(); |
||
| 280 | |||
| 281 | $response['message'] = 'success'; |
||
| 282 | } |
||
| 283 | |||
| 284 | $response['status'] = true; |
||
| 285 | |||
| 286 | return response()->json($response); |
||
| 287 | } |
||
| 288 | |||
| 308 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.