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 |
||
16 | class DJController extends Controller { |
||
17 | |||
18 | public function __construct() |
||
23 | |||
24 | /** |
||
25 | * Display a listing of the djs. |
||
26 | * |
||
27 | * @return Response |
||
28 | */ |
||
29 | public function index() |
||
34 | |||
35 | public function create() |
||
39 | |||
40 | /** |
||
41 | * Show the form for creating a new resource. |
||
42 | * |
||
43 | * @return Response |
||
44 | */ |
||
45 | View Code Duplication | public function store(Requests\CreateRequest $request) |
|
64 | |||
65 | /** |
||
66 | * Show the form for editing the specified resource. |
||
67 | * |
||
68 | * @param int $id |
||
69 | * @return Response |
||
70 | */ |
||
71 | public function edit($id) |
||
77 | |||
78 | /** |
||
79 | * Update the specified resource in storage. |
||
80 | * |
||
81 | * @param int $id |
||
82 | * @return Response |
||
83 | */ |
||
84 | View Code Duplication | public function update(Requests\UpdateRequest $request, $id) |
|
99 | |||
100 | /** |
||
101 | * Remove the specified resource from storage. |
||
102 | * |
||
103 | * @param int $id |
||
104 | * @return Response |
||
105 | */ |
||
106 | public function delete($id) |
||
119 | |||
120 | } |
||
121 |
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.