Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
22 | class OrangTuaController extends Controller |
||
23 | { |
||
24 | /** |
||
25 | * Create a new controller instance. |
||
26 | * |
||
27 | * @return void |
||
|
|||
28 | */ |
||
29 | public function __construct(OrangTua $orang_tua) |
||
33 | |||
34 | /** |
||
35 | * Display a listing of the resource. |
||
36 | * |
||
37 | * @return \Illuminate\Http\Response |
||
38 | */ |
||
39 | public function index(Request $request) |
||
64 | |||
65 | /** |
||
66 | * Show the form for creating a new resource. |
||
67 | * |
||
68 | * @return \Illuminate\Http\Response |
||
69 | */ |
||
70 | public function create() |
||
82 | |||
83 | /** |
||
84 | * Display the specified resource. |
||
85 | * |
||
86 | * @param \App\OrangTua $orang_tua |
||
87 | * @return \Illuminate\Http\Response |
||
88 | */ |
||
89 | public function store(Request $request) |
||
114 | |||
115 | /** |
||
116 | * Store a newly created resource in storage. |
||
117 | * |
||
118 | * @param \Illuminate\Http\Request $request |
||
119 | * @return \Illuminate\Http\Response |
||
120 | */ |
||
121 | View Code Duplication | public function show($id) |
|
130 | |||
131 | /** |
||
132 | * Show the form for editing the specified resource. |
||
133 | * |
||
134 | * @param \App\OrangTua $orang_tua |
||
135 | * @return \Illuminate\Http\Response |
||
136 | */ |
||
137 | View Code Duplication | public function edit($id) |
|
146 | |||
147 | /** |
||
148 | * Update the specified resource in storage. |
||
149 | * |
||
150 | * @param \Illuminate\Http\Request $request |
||
151 | * @param \App\OrangTua $orang_tua |
||
152 | * @return \Illuminate\Http\Response |
||
153 | */ |
||
154 | public function update(Request $request, $id) |
||
179 | |||
180 | /** |
||
181 | * Remove the specified resource from storage. |
||
182 | * |
||
183 | * @param \App\OrangTua $orang_tua |
||
184 | * @return \Illuminate\Http\Response |
||
185 | */ |
||
186 | View Code Duplication | public function destroy($id) |
|
198 | } |
||
199 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.