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 |
||
12 | class TarifController extends Controller |
||
13 | { |
||
14 | /** |
||
15 | * Display a listing of the resource. |
||
16 | * |
||
17 | * @return Response |
||
18 | */ |
||
19 | public function index() |
||
24 | |||
25 | /** |
||
26 | * Show the form for creating a new resource. |
||
27 | * |
||
28 | * @return Response |
||
29 | */ |
||
30 | public function create() |
||
36 | |||
37 | /** |
||
38 | * Store a newly created resource in storage. |
||
39 | * |
||
40 | * @return Response |
||
41 | */ |
||
42 | View Code Duplication | public function store(Request $request) |
|
83 | |||
84 | /** |
||
85 | * Display the specified resource. |
||
86 | * |
||
87 | * @param int $id |
||
88 | * @return Response |
||
89 | */ |
||
90 | public function show($id) |
||
94 | |||
95 | /** |
||
96 | * Show the form for editing the specified resource. |
||
97 | * |
||
98 | * @param int $id |
||
99 | * @return Response |
||
100 | */ |
||
101 | public function edit($id) |
||
107 | |||
108 | /** |
||
109 | * Update the specified resource in storage. |
||
110 | * |
||
111 | * @param int $id |
||
112 | * @return Response |
||
113 | */ |
||
114 | View Code Duplication | public function update(Request $request, $id) |
|
143 | |||
144 | /** |
||
145 | * Remove the specified resource from storage. |
||
146 | * |
||
147 | * @param int $id |
||
148 | * @return Response |
||
149 | */ |
||
150 | public function destroy(Request $request, $id) |
||
156 | |||
157 | } |
||
158 | |||
159 | ?> |
||
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.