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 |
||
23 | class LocationController extends Controller |
||
24 | { |
||
25 | protected $indonesia; |
||
26 | protected $province; |
||
27 | protected $city; |
||
28 | protected $district; |
||
29 | protected $village; |
||
30 | |||
31 | /** |
||
32 | * Create a new controller instance. |
||
33 | * |
||
34 | * @return void |
||
|
|||
35 | */ |
||
36 | public function __construct() |
||
44 | |||
45 | /** |
||
46 | * Display a listing of the province resource. |
||
47 | * |
||
48 | * @return \Illuminate\Http\Response |
||
49 | */ |
||
50 | View Code Duplication | public function allProvince() |
|
63 | |||
64 | /** |
||
65 | * Display a listing of the province resource. |
||
66 | * |
||
67 | * @return \Illuminate\Http\Response |
||
68 | */ |
||
69 | View Code Duplication | public function detailProvince($id) |
|
80 | |||
81 | /** |
||
82 | * Display a listing of the city resource. |
||
83 | * |
||
84 | * @return \Illuminate\Http\Response |
||
85 | */ |
||
86 | View Code Duplication | public function allCity() |
|
99 | |||
100 | /** |
||
101 | * Display a listing of the city resource. |
||
102 | * |
||
103 | * @return \Illuminate\Http\Response |
||
104 | */ |
||
105 | View Code Duplication | public function allCityByProvince($id) |
|
124 | |||
125 | /** |
||
126 | * Display a listing of the city resource. |
||
127 | * |
||
128 | * @return \Illuminate\Http\Response |
||
129 | */ |
||
130 | View Code Duplication | public function detailCity($id) |
|
141 | |||
142 | /** |
||
143 | * Display a listing of the district resource. |
||
144 | * |
||
145 | * @return \Illuminate\Http\Response |
||
146 | */ |
||
147 | View Code Duplication | public function allDistrict() |
|
160 | |||
161 | /** |
||
162 | * Display a listing of the district resource. |
||
163 | * |
||
164 | * @return \Illuminate\Http\Response |
||
165 | */ |
||
166 | View Code Duplication | public function allDistrictByCity($id) |
|
185 | |||
186 | /** |
||
187 | * Display a listing of the district resource. |
||
188 | * |
||
189 | * @return \Illuminate\Http\Response |
||
190 | */ |
||
191 | View Code Duplication | public function detailDistrict($id) |
|
202 | |||
203 | /** |
||
204 | * Display a listing of the village resource. |
||
205 | * |
||
206 | * @return \Illuminate\Http\Response |
||
207 | */ |
||
208 | View Code Duplication | public function allVillage() |
|
221 | |||
222 | /** |
||
223 | * Display a listing of the village resource. |
||
224 | * |
||
225 | * @return \Illuminate\Http\Response |
||
226 | */ |
||
227 | View Code Duplication | public function allVillageByDistrict($id) |
|
246 | |||
247 | /** |
||
248 | * Display a listing of the village resource. |
||
249 | * |
||
250 | * @return \Illuminate\Http\Response |
||
251 | */ |
||
252 | View Code Duplication | public function detailVillage($id) |
|
263 | } |
||
264 |
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.