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 |
||
13 | class ThemesController extends Controller |
||
14 | { |
||
15 | private $pagination = 50; |
||
16 | |||
17 | /** |
||
18 | * Display a listing of the resource. |
||
19 | * |
||
20 | * @param \Illuminate\Http\Request $request |
||
21 | * |
||
22 | * @return \Illuminate\Http\Response |
||
23 | */ |
||
24 | public function index(Request $request) |
||
28 | |||
29 | /** |
||
30 | * Show the form for creating a new resource. |
||
31 | * |
||
32 | * @return \Illuminate\Http\Response |
||
33 | */ |
||
34 | public function create() |
||
38 | |||
39 | /** |
||
40 | * Store a newly created resource in storage. |
||
41 | * |
||
42 | * @param ThemeFormRequest $request |
||
43 | * |
||
44 | * @return \Illuminate\Http\RedirectResponse |
||
45 | */ |
||
46 | View Code Duplication | public function store(ThemeFormRequest $request) |
|
66 | |||
67 | /** |
||
68 | * Show the form for editing the specified resource. |
||
69 | * |
||
70 | * @param \App\Models\Theme $theme |
||
71 | * |
||
72 | * @return void |
||
73 | */ |
||
74 | public function edit(Theme $theme) |
||
78 | |||
79 | /** |
||
80 | * Update the specified resource in storage. |
||
81 | * |
||
82 | * @param \App\Http\Requests\ThemeFormRequest $request |
||
83 | * @param \App\Models\Theme $theme |
||
84 | * |
||
85 | * @return \Illuminate\Http\RedirectResponse |
||
86 | */ |
||
87 | View Code Duplication | public function update(ThemeFormRequest $request, Theme $theme) |
|
105 | |||
106 | /** |
||
107 | * Remove the specified resource from storage. |
||
108 | * |
||
109 | * @param \Illuminate\Http\Request $request |
||
110 | * @param \App\Models\Theme $theme |
||
111 | * |
||
112 | * @return array |
||
113 | * @throws \Exception |
||
114 | */ |
||
115 | public function destroy(Request $request, Theme $theme) |
||
143 | |||
144 | View Code Duplication | public function resource(Request $request) |
|
154 | } |
||
155 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.