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 |
||
| 34 | class MembersRequestBuilder extends CoreRequestBuilder { |
||
| 35 | |||
| 36 | const TABLE_GROUPS = 'circles_groups'; |
||
| 37 | const TABLE_MEMBERS = 'circles_members'; |
||
| 38 | |||
| 39 | |||
| 40 | /** |
||
| 41 | * Limit the request to a minimum member level. |
||
| 42 | * |
||
| 43 | * @param IQueryBuilder $qb |
||
| 44 | * @param integer $level |
||
| 45 | */ |
||
| 46 | protected function limitToMemberLevel(IQueryBuilder & $qb, $level) { |
||
| 53 | |||
| 54 | |||
| 55 | /** |
||
| 56 | * @return IQueryBuilder |
||
| 57 | */ |
||
| 58 | protected function getGroupsSelectSql() { |
||
| 68 | |||
| 69 | |||
| 70 | /** |
||
| 71 | * Base of the Sql Insert request for Shares |
||
| 72 | * |
||
| 73 | * @return IQueryBuilder |
||
| 74 | */ |
||
| 75 | View Code Duplication | protected function getGroupsInsertSql() { |
|
| 82 | |||
| 83 | |||
| 84 | /** |
||
| 85 | * Base of the Sql Insert request for Shares |
||
| 86 | * |
||
| 87 | * @param int $circleId |
||
| 88 | * @param string $groupId |
||
| 89 | * |
||
| 90 | * @return IQueryBuilder |
||
| 91 | */ |
||
| 92 | protected function getGroupsUpdateSql($circleId, $groupId) { |
||
| 107 | |||
| 108 | |||
| 109 | /** |
||
| 110 | * Base of the Sql Insert request for Shares |
||
| 111 | * |
||
| 112 | * @param string $groupId |
||
| 113 | * |
||
| 114 | * @return IQueryBuilder |
||
| 115 | */ |
||
| 116 | View Code Duplication | protected function getGroupsDeleteSql($groupId) { |
|
| 125 | |||
| 126 | |||
| 127 | } |
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.