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 namespace WITR\Http\Controllers\Admin; |
||
9 | class AlbumReviewController extends Controller { |
||
10 | |||
11 | public function __construct() |
||
16 | |||
17 | /** |
||
18 | * Display a listing of the Album Reviews. |
||
19 | * |
||
20 | * @return Response |
||
21 | */ |
||
22 | public function index() |
||
27 | |||
28 | /** |
||
29 | * Display a listing of the resource. |
||
30 | * |
||
31 | * @return Response |
||
32 | */ |
||
33 | public function new_review() |
||
37 | |||
38 | /** |
||
39 | * Save the new Album Review. |
||
40 | * |
||
41 | *@return Response |
||
42 | */ |
||
43 | public function create(Requests\CreateRequest $request) |
||
54 | |||
55 | public function edit($id) |
||
61 | |||
62 | View Code Duplication | public function update(Requests\UpdateRequest $request, $id) |
|
77 | |||
78 | View Code Duplication | public function delete($id) |
|
86 | |||
87 | } |
||
88 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.