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:
Complex classes like ProjectController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ProjectController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 33 | class ProjectController extends Controller |
||
| 34 | { |
||
| 35 | protected function indexView($data, $active, ProjectRepository $project) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Display activity for a project. |
||
| 56 | * |
||
| 57 | * @param ProjectRepository $project |
||
| 58 | * |
||
| 59 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 60 | */ |
||
| 61 | View Code Duplication | public function getIndex(ProjectRepository $project) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * Display issues for a project. |
||
| 75 | * |
||
| 76 | * @param FilterForm $filterForm |
||
| 77 | * @param Request $request |
||
| 78 | * @param ProjectRepository $project |
||
| 79 | * @param int $status |
||
| 80 | * |
||
| 81 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 82 | */ |
||
| 83 | public function getIssues(FilterForm $filterForm, Request $request, ProjectRepository $project, $status = Issue::STATUS_OPEN) |
||
| 102 | |||
| 103 | protected function getOpenIssuesViewData(Collection $issues, ProjectRepository $project) |
||
| 111 | |||
| 112 | protected function getClosedIssuesViewData(Collection $issues, ProjectRepository $project) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Display issues assigned to current user for a project. |
||
| 123 | * |
||
| 124 | * @param ProjectRepository $project |
||
| 125 | * |
||
| 126 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 127 | */ |
||
| 128 | View Code Duplication | public function getAssigned(ProjectRepository $project) |
|
| 140 | |||
| 141 | /** |
||
| 142 | * Display issues created to current user for a project. |
||
| 143 | * |
||
| 144 | * @param ProjectRepository $project |
||
| 145 | * |
||
| 146 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 147 | */ |
||
| 148 | View Code Duplication | public function getCreated(ProjectRepository $project) |
|
| 160 | |||
| 161 | /** |
||
| 162 | * Display notes for a project. |
||
| 163 | * |
||
| 164 | * @param ProjectRepository $project |
||
| 165 | * @param NoteForm $form |
||
| 166 | * |
||
| 167 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 168 | */ |
||
| 169 | View Code Duplication | public function getNotes(ProjectRepository $project, NoteForm $form) |
|
| 181 | |||
| 182 | /** |
||
| 183 | * @param Project $project |
||
| 184 | * @param string $view |
||
| 185 | * @param null $data |
||
| 186 | * @param bool $status |
||
| 187 | * |
||
| 188 | * @return array |
||
| 189 | */ |
||
| 190 | protected function projectMainViewTabs(ProjectRepository $project, $view, $data = null, $status = false) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Edit the project. |
||
| 257 | * |
||
| 258 | * @param Project $project |
||
| 259 | * @param Form $form |
||
| 260 | * |
||
| 261 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 262 | */ |
||
| 263 | public function getEdit(ProjectRepository $project, Form $form) |
||
| 271 | |||
| 272 | /** |
||
| 273 | * To update project details. |
||
| 274 | * |
||
| 275 | * @param Project $project |
||
| 276 | * @param FormRequest\Project $request |
||
| 277 | * |
||
| 278 | * @return \Illuminate\Http\RedirectResponse |
||
| 279 | */ |
||
| 280 | public function postEdit(ProjectRepository $project, FormRequest\Project $request) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Ajax: returns list of users that are not in the project. |
||
| 298 | * |
||
| 299 | * @param Project $project |
||
| 300 | * |
||
| 301 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 302 | */ |
||
| 303 | public function getInactiveUsers(ProjectRepository $project) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Ajax: add user to the project. |
||
| 312 | * |
||
| 313 | * @param Project $project |
||
| 314 | * @param Request $request |
||
| 315 | * |
||
| 316 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 317 | */ |
||
| 318 | public function postAssign(ProjectRepository $project, Request $request) |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Ajax: remove user from the project. |
||
| 327 | * |
||
| 328 | * @param Project $project |
||
| 329 | * @param Request $request |
||
| 330 | * |
||
| 331 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 332 | */ |
||
| 333 | public function postUnassign(RoleRepository $project, Request $request) |
||
| 339 | |||
| 340 | /** |
||
| 341 | * To add a new note to the project. |
||
| 342 | * |
||
| 343 | * @param Project $project |
||
| 344 | * @param Note $note |
||
| 345 | * @param FormRequest\Note $request |
||
| 346 | * |
||
| 347 | * @return \Illuminate\Http\RedirectResponse |
||
| 348 | */ |
||
| 349 | public function postAddNote(ProjectRepository $project, NoteRepository $note, FormRequest\Note $request) |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Ajax: To update project note. |
||
| 360 | * |
||
| 361 | * @param Project $project |
||
| 362 | * @param Note $note |
||
| 363 | * @param Request $request |
||
| 364 | * |
||
| 365 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 366 | */ |
||
| 367 | public function postEditNote(ProjectRepository $project, \Tinyissue\Contracts\Repository\Project\NoteRepository $note, Request $request) |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Ajax: to delete a project note. |
||
| 382 | * |
||
| 383 | * @param Project $project |
||
| 384 | * @param Note $note |
||
| 385 | * |
||
| 386 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 387 | */ |
||
| 388 | public function getDeleteNote(ProjectRepository $project, \Tinyissue\Contracts\Repository\Project\NoteRepository $note) |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Ajax: generate the issues export file. |
||
| 397 | * |
||
| 398 | * @param Project $project |
||
| 399 | * @param Exporter $exporter |
||
| 400 | * @param Request $request |
||
| 401 | * |
||
| 402 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 403 | */ |
||
| 404 | public function postExportIssues(ProjectRepository $project, Exporter $exporter, Request $request) |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Download and then delete an export file. |
||
| 430 | * |
||
| 431 | * @param Project $project |
||
| 432 | * @param string $file |
||
| 433 | * |
||
| 434 | * @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
||
| 435 | */ |
||
| 436 | public function getDownloadExport(ProjectRepository $project, $file) |
||
| 444 | } |
||
| 445 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.