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; |
||
10 | View Code Duplication | class VideoController extends Controller { |
|
|
|||
11 | |||
12 | public function __construct() |
||
17 | |||
18 | /** |
||
19 | * Display a listing of the Videos. |
||
20 | * |
||
21 | * @return Response |
||
22 | */ |
||
23 | public function index() |
||
28 | |||
29 | /** |
||
30 | * Display a listing of the resource. |
||
31 | * |
||
32 | * @return Response |
||
33 | */ |
||
34 | public function new_review() |
||
38 | |||
39 | /** |
||
40 | * Save the new eboard position. |
||
41 | * |
||
42 | *@return Response |
||
43 | */ |
||
44 | public function create(Requests\CreateRequest $request) |
||
52 | |||
53 | public function edit($id) |
||
59 | |||
60 | public function update(Requests\UpdateRequest $request, $id) |
||
68 | |||
69 | public function delete($id) |
||
75 | |||
76 | } |
||
77 |
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.