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 DashboardWidgetController extends Controller | ||
| 13 | { | ||
| 14 | |||
| 15 | use Helpers; | ||
| 16 | |||
| 17 |     public function __construct() { | ||
| 20 | |||
| 21 | /** | ||
| 22 | * Display a listing of all authorized devices | ||
| 23 | * | ||
| 24 | * @return \Illuminate\Http\Response | ||
| 25 | */ | ||
| 26 | public function index(Request $request) | ||
| 30 | |||
| 31 | /** | ||
| 32 | * Show the form for creating a new resource. | ||
| 33 | * | ||
| 34 | * @return \Illuminate\Http\Response | ||
| 35 | */ | ||
| 36 | public function create() | ||
| 40 | |||
| 41 | /** | ||
| 42 | * Store a newly created resource in storage. | ||
| 43 | * | ||
| 44 | * @param \Illuminate\Http\Request $request | ||
| 45 | * @return \Illuminate\Http\Response | ||
| 46 | */ | ||
| 47 | public function store(Request $request) | ||
| 67 | |||
| 68 | /** | ||
| 69 | * Display the specified resource. | ||
| 70 | * | ||
| 71 | * @param int $id | ||
| 72 | * @return \Illuminate\Http\Response | ||
| 73 | */ | ||
| 74 | public function show(Request $request, $id) | ||
| 80 | |||
| 81 | /** | ||
| 82 | * Show the form for editing the specified resource. | ||
| 83 | * | ||
| 84 | * @param int $id | ||
| 85 | * @return \Illuminate\Http\Response | ||
| 86 | */ | ||
| 87 | public function edit($id) | ||
| 91 | |||
| 92 | /** | ||
| 93 | * Update the specified resource in storage. | ||
| 94 | * | ||
| 95 | * @param \Illuminate\Http\Request $request | ||
| 96 | * @param int $id | ||
| 97 | * @return \Illuminate\Http\Response | ||
| 98 | */ | ||
| 99 | public function update(Request $request, $id) | ||
| 114 | |||
| 115 | /** | ||
| 116 | * Remove the specified resource from storage. | ||
| 117 | * | ||
| 118 | * @param int $id | ||
| 119 | * @return \Illuminate\Http\Response | ||
| 120 | */ | ||
| 121 | public function destroy($id) | ||
| 131 | |||
| 132 | public function get_content($id) | ||
| 137 | |||
| 138 | public function get_settings($id) | ||
| 143 | |||
| 144 | } | ||
| 145 | 
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.