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 |
||
| 29 | class ProjectController extends Controller |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * Display activity for a project |
||
| 33 | * |
||
| 34 | * @param Project $project |
||
| 35 | * |
||
| 36 | * @return \Illuminate\View\View |
||
| 37 | */ |
||
| 38 | 9 | public function getIndex(Project $project) |
|
| 54 | |||
| 55 | /** |
||
| 56 | * Display issues for a project |
||
| 57 | * |
||
| 58 | * @param FilterForm $filterForm |
||
| 59 | * @param Request $request |
||
| 60 | * @param Project $project |
||
| 61 | * @param int $status |
||
| 62 | * |
||
| 63 | * @return \Illuminate\View\View |
||
| 64 | */ |
||
| 65 | 2 | public function getIssues(FilterForm $filterForm, Request $request, Project $project, $status = Issue::STATUS_OPEN) |
|
| 79 | |||
| 80 | /** |
||
| 81 | * Display issues assigned to current user for a project |
||
| 82 | * |
||
| 83 | * @param Project $project |
||
| 84 | * |
||
| 85 | * @return \Illuminate\View\View |
||
| 86 | */ |
||
| 87 | 1 | public function getAssigned(Project $project) |
|
| 99 | |||
| 100 | /** |
||
| 101 | * Display notes for a project |
||
| 102 | * |
||
| 103 | * @param Project $project |
||
| 104 | * @param NoteForm $form |
||
| 105 | * |
||
| 106 | * @return \Illuminate\View\View |
||
| 107 | */ |
||
| 108 | 7 | public function getNotes(Project $project, NoteForm $form) |
|
| 121 | |||
| 122 | /** |
||
| 123 | * @param Project $project |
||
| 124 | * @param $view |
||
| 125 | * @param null $data |
||
| 126 | * @param bool $status |
||
| 127 | * @return array |
||
| 128 | */ |
||
| 129 | 19 | protected function projectMainViewTabs(Project $project, $view, $data = null, $status = false) |
|
| 183 | |||
| 184 | /** |
||
| 185 | * Edit the project |
||
| 186 | * |
||
| 187 | * @param Project $project |
||
| 188 | * @param Form $form |
||
| 189 | * |
||
| 190 | * @return \Illuminate\View\View |
||
| 191 | */ |
||
| 192 | 2 | public function getEdit(Project $project, Form $form) |
|
| 200 | |||
| 201 | /** |
||
| 202 | * To update project details |
||
| 203 | * |
||
| 204 | * @param Project $project |
||
| 205 | * @param FormRequest\Project $request |
||
| 206 | * |
||
| 207 | * @return \Illuminate\Http\RedirectResponse |
||
| 208 | */ |
||
| 209 | 2 | public function postEdit(Project $project, FormRequest\Project $request) |
|
| 224 | |||
| 225 | /** |
||
| 226 | * Ajax: returns list of users that are not in the project |
||
| 227 | * |
||
| 228 | * @param Project $project |
||
| 229 | * |
||
| 230 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 231 | */ |
||
| 232 | 1 | public function getInactiveUsers(Project $project) |
|
| 238 | |||
| 239 | /** |
||
| 240 | * Ajax: add user to the project |
||
| 241 | * |
||
| 242 | * @param Project $project |
||
| 243 | * @param Request $request |
||
| 244 | * |
||
| 245 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 246 | */ |
||
| 247 | 1 | View Code Duplication | public function postAssign(Project $project, Request $request) |
| 257 | |||
| 258 | /** |
||
| 259 | * Ajax: remove user from the project |
||
| 260 | * |
||
| 261 | * @param Project $project |
||
| 262 | * @param Request $request |
||
| 263 | * |
||
| 264 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 265 | */ |
||
| 266 | 1 | View Code Duplication | public function postUnassign(Project $project, Request $request) |
| 276 | |||
| 277 | /** |
||
| 278 | * To add a new note to the project |
||
| 279 | * |
||
| 280 | * @param Project $project |
||
| 281 | * @param Note $note |
||
| 282 | * @param FormRequest\Note $request |
||
| 283 | * |
||
| 284 | * @return \Illuminate\Http\RedirectResponse |
||
| 285 | */ |
||
| 286 | 2 | public function postAddNote(Project $project, Note $note, FormRequest\Note $request) |
|
| 294 | |||
| 295 | /** |
||
| 296 | * Ajax: To update project note |
||
| 297 | * |
||
| 298 | * @param Project $project |
||
| 299 | * @param Note $note |
||
| 300 | * @param Request $request |
||
| 301 | * |
||
| 302 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 303 | */ |
||
| 304 | 1 | public function postEditNote(Project $project, Project\Note $note, Request $request) |
|
| 316 | |||
| 317 | /** |
||
| 318 | * Ajax: to delete a project note |
||
| 319 | * |
||
| 320 | * @param Project $project |
||
| 321 | * @param Note $note |
||
| 322 | * |
||
| 323 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 324 | */ |
||
| 325 | 1 | public function getDeleteNote(Project $project, Project\Note $note) |
|
| 331 | |||
| 332 | /** |
||
| 333 | * Ajax: generate the issues export file |
||
| 334 | * |
||
| 335 | * @param Project $project |
||
| 336 | * @param Exporter $exporter |
||
| 337 | * @param Request $request |
||
| 338 | * |
||
| 339 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 340 | */ |
||
| 341 | 4 | public function postExportIssues(Project $project, Exporter $exporter, Request $request) |
|
| 364 | |||
| 365 | /** |
||
| 366 | * Download and then delete an export file |
||
| 367 | * |
||
| 368 | * @param Project $project |
||
| 369 | * @param string $file |
||
| 370 | * |
||
| 371 | * @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
||
| 372 | */ |
||
| 373 | 4 | public function getDownloadExport(Project $project, $file) |
|
| 381 | } |
||
| 382 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: