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 |
||
| 9 | View Code Duplication | trait ListHandlerTrait |
|
|
|
|||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Show table list page. |
||
| 13 | * |
||
| 14 | * @param Request $request |
||
| 15 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 16 | * @throws UnauthorizedException |
||
| 17 | */ |
||
| 18 | 1 | public function handleList(Request $request) |
|
| 34 | |||
| 35 | /** |
||
| 36 | * Get array of view's objects, that should be rendered above content of `list` view. |
||
| 37 | * |
||
| 38 | * @return array |
||
| 39 | */ |
||
| 40 | 2 | protected function getListViewsAbove(): array |
|
| 44 | |||
| 45 | /** |
||
| 46 | * Get array of view's objects, that should be rendered below content of `list` view. |
||
| 47 | * |
||
| 48 | * @return array |
||
| 49 | */ |
||
| 50 | 2 | protected function getListViewsBelow(): array |
|
| 54 | |||
| 55 | abstract protected function init(); |
||
| 59 | } |
||
| 60 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.