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 |
||
| 24 | class JobTitlesController extends BaseController |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var JobTitle |
||
| 28 | */ |
||
| 29 | protected $job_title; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param JobTitle $job_title |
||
| 33 | * |
||
| 34 | * @author Bertrand Kintanar <[email protected]> |
||
| 35 | */ |
||
| 36 | 14 | public function __construct(JobTitle $job_title) |
|
| 40 | |||
| 41 | /** |
||
| 42 | * Delete the PIM - Custom Field Section. |
||
| 43 | * |
||
| 44 | * @param JobTitleRequest $request |
||
| 45 | * |
||
| 46 | * @return \Illuminate\Http\RedirectResponse |
||
| 47 | * |
||
| 48 | * @author Bertrand Kintanar <[email protected]> |
||
| 49 | */ |
||
| 50 | 4 | public function destroy(JobTitleRequest $request) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * Show a PIM - Custom Field Section. |
||
| 65 | * |
||
| 66 | * @param JobRequest $request |
||
| 67 | * |
||
| 68 | * @return \Illuminate\View\View |
||
| 69 | * |
||
| 70 | * @author Bertrand Kintanar <[email protected]> |
||
| 71 | */ |
||
| 72 | 2 | public function index(JobRequest $request) |
|
| 83 | |||
| 84 | /** |
||
| 85 | * Save the PIM - Custom Field Section. |
||
| 86 | * |
||
| 87 | * @param JobTitleRequest $request |
||
| 88 | * |
||
| 89 | * @return \Illuminate\Http\RedirectResponse |
||
| 90 | * |
||
| 91 | * @author Bertrand Kintanar <[email protected]> |
||
| 92 | */ |
||
| 93 | 6 | View Code Duplication | public function store(JobTitleRequest $request) |
| 103 | |||
| 104 | /** |
||
| 105 | * Setup table for custom field section. |
||
| 106 | * |
||
| 107 | * @param $job_titles |
||
| 108 | * |
||
| 109 | * @return array |
||
| 110 | * |
||
| 111 | * @author Bertrand Kintanar <[email protected]> |
||
| 112 | */ |
||
| 113 | 2 | View Code Duplication | public function setupDataTable($job_titles) |
| 129 | |||
| 130 | /** |
||
| 131 | * Update the PIM - Custom Field Section. |
||
| 132 | * |
||
| 133 | * @param JobTitleRequest $request |
||
| 134 | * |
||
| 135 | * @return \Illuminate\Http\RedirectResponse |
||
| 136 | * |
||
| 137 | * @author Bertrand Kintanar <[email protected]> |
||
| 138 | */ |
||
| 139 | 4 | View Code Duplication | public function update(JobTitleRequest $request) |
| 156 | } |
||
| 157 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: