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 | |||
| 37 | /** |
||
| 38 | * Base of the Sql Insert request for Shares |
||
| 39 | * |
||
| 40 | * @return IQueryBuilder |
||
| 41 | */ |
||
| 42 | View Code Duplication | protected function getMembersInsertSql() { |
|
| 49 | |||
| 50 | |||
| 51 | /** |
||
| 52 | * @return IQueryBuilder |
||
| 53 | */ |
||
| 54 | protected function getMembersSelectSql() { |
||
| 65 | |||
| 66 | |||
| 67 | /** |
||
| 68 | * @return IQueryBuilder |
||
| 69 | */ |
||
| 70 | protected function getGroupsSelectSql() { |
||
| 80 | |||
| 81 | |||
| 82 | /** |
||
| 83 | * Base of the Sql Insert request for Shares |
||
| 84 | * |
||
| 85 | * @return IQueryBuilder |
||
| 86 | */ |
||
| 87 | View Code Duplication | protected function getGroupsInsertSql() { |
|
| 94 | |||
| 95 | |||
| 96 | /** |
||
| 97 | * Base of the Sql Update request for Groups |
||
| 98 | * |
||
| 99 | * @param int $circleId |
||
| 100 | * @param string $groupId |
||
| 101 | * |
||
| 102 | * @return IQueryBuilder |
||
| 103 | */ |
||
| 104 | View Code Duplication | protected function getGroupsUpdateSql($circleId, $groupId) { |
|
| 119 | |||
| 120 | /** |
||
| 121 | * Base of the Sql Updte request for Members |
||
| 122 | * |
||
| 123 | * @param int $circleId |
||
| 124 | * @param string $userId |
||
| 125 | * |
||
| 126 | * @return IQueryBuilder |
||
| 127 | */ |
||
| 128 | View Code Duplication | protected function getMembersUpdateSql($circleId, $userId) { |
|
| 143 | |||
| 144 | |||
| 145 | /** |
||
| 146 | * Base of the Sql Delete request for Groups |
||
| 147 | * |
||
| 148 | * @param string $groupId |
||
| 149 | * |
||
| 150 | * @return IQueryBuilder |
||
| 151 | */ |
||
| 152 | View Code Duplication | protected function getGroupsDeleteSql($groupId) { |
|
| 161 | |||
| 162 | /** |
||
| 163 | * Base of the Sql Delete request for Members |
||
| 164 | * |
||
| 165 | * @param int $circleId |
||
| 166 | * @param string $userId |
||
| 167 | * |
||
| 168 | * @return IQueryBuilder |
||
| 169 | */ |
||
| 170 | protected function getMembersDeleteSql($circleId, $userId) { |
||
| 187 | |||
| 188 | |||
| 189 | /** |
||
| 190 | * @param array $data |
||
| 191 | * |
||
| 192 | * @return Member |
||
| 193 | */ |
||
| 194 | View Code Duplication | protected function parseMembersSelectSql(array $data) { |
|
| 205 | |||
| 206 | /** |
||
| 207 | * @param array $data |
||
| 208 | * |
||
| 209 | * @return Member |
||
| 210 | */ |
||
| 211 | View Code Duplication | protected function parseGroupsSelectSql(array $data) { |
|
| 226 | |||
| 227 | } |
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.