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 |
||
| 39 | class GroupManagement extends Action { |
||
| 40 | |||
| 41 | /** |
||
| 42 | * log add user to group event |
||
| 43 | * |
||
| 44 | * @param IGroup $group |
||
| 45 | * @param IUser $user |
||
| 46 | */ |
||
| 47 | View Code Duplication | public function addUser(IGroup $group, IUser $user) { |
|
| 58 | |||
| 59 | /** |
||
| 60 | * log remove user from group event |
||
| 61 | * |
||
| 62 | * @param IGroup $group |
||
| 63 | * @param IUser $user |
||
| 64 | */ |
||
| 65 | View Code Duplication | public function removeUser(IGroup $group, IUser $user) { |
|
| 76 | |||
| 77 | /** |
||
| 78 | * log create group to group event |
||
| 79 | * |
||
| 80 | * @param IGroup $group |
||
| 81 | */ |
||
| 82 | public function createGroup(IGroup $group) { |
||
| 92 | |||
| 93 | /** |
||
| 94 | * log delete group to group event |
||
| 95 | * |
||
| 96 | * @param IGroup $group |
||
| 97 | */ |
||
| 98 | public function deleteGroup(IGroup $group) { |
||
| 108 | } |
||
| 109 |
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.