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 User extends AdminController |
||
16 | { |
||
17 | const VERSION = '1.0.0'; |
||
18 | const ITEM_PER_PAGE = 10; |
||
19 | |||
20 | public $type = 'app'; |
||
21 | |||
22 | use User\ActionIndex { |
||
23 | index as actionIndex; |
||
24 | } |
||
25 | |||
26 | use User\ActionUpdate { |
||
27 | update as actionUpdate; |
||
28 | } |
||
29 | |||
30 | use User\ActionDelete { |
||
31 | delete as actionDelete; |
||
32 | } |
||
33 | |||
34 | use User\ActionInvite { |
||
35 | invite as actionInvite; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Show all role groups |
||
40 | * @return string |
||
41 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
42 | */ |
||
43 | public function actionGrouplist() |
||
52 | |||
53 | /** |
||
54 | * Edit and add groups |
||
55 | * @param int $id |
||
56 | * @return string |
||
57 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
58 | */ |
||
59 | public function actionGroupUpdate($id) |
||
79 | |||
80 | /** |
||
81 | * User identity settings |
||
82 | * @return string |
||
83 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
84 | */ |
||
85 | View Code Duplication | public function actionSettings() |
|
105 | } |
||
106 |
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.