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 StaffController extends Controller |
||
| 17 | { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * StaffController constructor. |
||
| 21 | */ |
||
| 22 | public function __construct() |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Create new staff member. |
||
| 30 | * |
||
| 31 | * @TODO Build up the view |
||
| 32 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 33 | */ |
||
| 34 | public function create() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Store the new member in the database |
||
| 41 | * |
||
| 42 | * @TODO: Needs phpunit test. |
||
| 43 | * @TODO: Build up the controller logic. |
||
| 44 | * @TODO: Build up the request validator. |
||
| 45 | * @return \Illuminate\Http\RedirectResponse |
||
| 46 | */ |
||
| 47 | public function store() |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Update the staff member. |
||
| 54 | * |
||
| 55 | * @TODO: Needs phpunit test |
||
| 56 | * @TODO: Build up the controller. |
||
| 57 | * @TODO: BUild up the request validator. |
||
| 58 | * @param int $id The staff member id in the database. |
||
| 59 | * @return \Illuminate\Http\RedirectResponse |
||
| 60 | */ |
||
| 61 | public function update($id) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Edit view for a staff member. |
||
| 68 | * |
||
| 69 | * @TODO Build up the view. |
||
| 70 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 71 | */ |
||
| 72 | public function edit($id) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Display all the staff. |
||
| 80 | * |
||
| 81 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 82 | */ |
||
| 83 | public function index() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Set the user available. |
||
| 91 | * |
||
| 92 | * @return \Illuminate\Http\RedirectResponse |
||
| 93 | */ |
||
| 94 | View Code Duplication | public function setAvailable() |
|
| 102 | |||
| 103 | /** |
||
| 104 | * Set the user unavailable. |
||
| 105 | * |
||
| 106 | * @return \Illuminate\Http\RedirectResponse |
||
| 107 | */ |
||
| 108 | View Code Duplication | public function setUnavailable() |
|
| 116 | |||
| 117 | /** |
||
| 118 | * Display the profile. |
||
| 119 | * |
||
| 120 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 121 | */ |
||
| 122 | public function profile() |
||
| 123 | { |
||
| 124 | $id = auth()->user()->id; |
||
| 125 | $data['tokens'] = ApiKey::where('user_id', $id)->get(); |
||
| 126 | return view('users/profile', $data); |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Destroy or multiple staff members. |
||
| 131 | * |
||
| 132 | * @param int $id THe id off the staff member in the database. |
||
| 133 | * @return \Illuminate\Http\RedirectResponse |
||
| 134 | */ |
||
| 135 | public function destroy($id) |
||
| 145 | |||
| 146 | View Code Duplication | public function get_roles() |
|
| 160 | |||
| 161 | } |
||
| 162 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.