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 CategoriesController extends Controller |
||
14 | { |
||
15 | private $pagination = 50; |
||
16 | |||
17 | /** |
||
18 | * Display a listing of the resource. |
||
19 | * |
||
20 | * @param \Illuminate\Http\Request $request |
||
21 | * @return \Illuminate\Http\Response |
||
22 | */ |
||
23 | public function index(Request $request) |
||
27 | |||
28 | /** |
||
29 | * Show the form for creating a new resource. |
||
30 | * |
||
31 | * @return \Illuminate\Http\Response |
||
32 | */ |
||
33 | public function create() |
||
37 | |||
38 | /** |
||
39 | * Store a newly created resource in storage. |
||
40 | * |
||
41 | * @param \Illuminate\Http\Request $request |
||
42 | * |
||
43 | * @return \Illuminate\Http\RedirectResponse |
||
44 | */ |
||
45 | View Code Duplication | public function store(CategoryFormRequest $request) |
|
58 | |||
59 | /** |
||
60 | * Show the form for editing the specified resource. |
||
61 | * |
||
62 | * @param \App\Models\Category $category |
||
63 | * |
||
64 | * @return void |
||
65 | */ |
||
66 | public function edit(Category $category) |
||
70 | |||
71 | /** |
||
72 | * Update the specified resource in storage. |
||
73 | * |
||
74 | * @param \Illuminate\Http\Request $request |
||
75 | * @param \App\Models\Category $category |
||
76 | * |
||
77 | * @return \Illuminate\Http\RedirectResponse |
||
78 | */ |
||
79 | View Code Duplication | public function update(CategoryFormRequest $request, Category $category) |
|
91 | |||
92 | /** |
||
93 | * Remove the specified resource from storage. |
||
94 | * |
||
95 | * @param \Illuminate\Http\Request $request |
||
96 | * @param \App\Models\Category $category |
||
97 | * |
||
98 | * @return array |
||
99 | * @throws \Exception |
||
100 | */ |
||
101 | public function destroy(Request $request, Category $category) |
||
121 | |||
122 | View Code Duplication | public function resource(Request $request) |
|
132 | } |
||
133 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.