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 |
||
| 15 | class StaffController extends Controller |
||
| 16 | { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * StaffController constructor. |
||
| 20 | */ |
||
| 21 | public function __construct() |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Create new staff member. |
||
| 29 | * |
||
| 30 | * @TODO Build up the view |
||
| 31 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 32 | */ |
||
| 33 | public function create() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Store the new member in the database |
||
| 40 | * |
||
| 41 | * @TODO: Needs phpunit test. |
||
| 42 | * @TODO: Build up the controller logic. |
||
| 43 | * @TODO: Build up the request validator. |
||
| 44 | * @return \Illuminate\Http\RedirectResponse |
||
| 45 | */ |
||
| 46 | public function store() |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Update the staff member. |
||
| 53 | * |
||
| 54 | * @TODO: Needs phpunit test |
||
| 55 | * @TODO: Build up the controller. |
||
| 56 | * @TODO: BUild up the request validator. |
||
| 57 | * @param int $id The staff member id in the database. |
||
| 58 | * @return \Illuminate\Http\RedirectResponse |
||
| 59 | */ |
||
| 60 | public function update($id) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Edit view for a staff member. |
||
| 67 | * |
||
| 68 | * @TODO Build up the view. |
||
| 69 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 70 | */ |
||
| 71 | public function edit($id) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Display all the staff. |
||
| 79 | * |
||
| 80 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 81 | */ |
||
| 82 | public function index() |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Set the user available. |
||
| 90 | * |
||
| 91 | * @return \Illuminate\Http\RedirectResponse |
||
| 92 | */ |
||
| 93 | View Code Duplication | public function setAvailable() |
|
| 101 | |||
| 102 | /** |
||
| 103 | * Set the user unavailable. |
||
| 104 | * |
||
| 105 | * @return \Illuminate\Http\RedirectResponse |
||
| 106 | */ |
||
| 107 | View Code Duplication | public function setUnavailable() |
|
| 115 | |||
| 116 | /** |
||
| 117 | * Display the profile. |
||
| 118 | * |
||
| 119 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 120 | */ |
||
| 121 | public function profile() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Destroy or multiple staff members. |
||
| 128 | * |
||
| 129 | * @param int $id THe id off the staff member in the database. |
||
| 130 | * @return \Illuminate\Http\RedirectResponse |
||
| 131 | */ |
||
| 132 | public function destroy($id) |
||
| 142 | } |
||
| 143 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.