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 |
||
| 40 | class CirclesRequestBuilder { |
||
|
|
|||
| 41 | |||
| 42 | const TABLE_CIRCLES = 'circles_circles'; |
||
| 43 | const TABLE_MEMBERS = 'circles_members'; |
||
| 44 | |||
| 45 | /** @var IDBConnection */ |
||
| 46 | protected $dbConnection; |
||
| 47 | |||
| 48 | /** @var L10N */ |
||
| 49 | protected $l10n; |
||
| 50 | |||
| 51 | private $default_select_alias; |
||
| 52 | |||
| 53 | |||
| 54 | /** |
||
| 55 | * Join the Circles table |
||
| 56 | * |
||
| 57 | * @param IQueryBuilder $qb |
||
| 58 | * @param string $field |
||
| 59 | */ |
||
| 60 | protected function joinCircles(& $qb, $field) { |
||
| 66 | |||
| 67 | |||
| 68 | /** |
||
| 69 | * Limit the request to the Share by its Id. |
||
| 70 | * |
||
| 71 | * @param IQueryBuilder $qb |
||
| 72 | * @param int $circleId |
||
| 73 | */ |
||
| 74 | protected function limitToCircleId(IQueryBuilder & $qb, $circleId) { |
||
| 80 | |||
| 81 | |||
| 82 | /** |
||
| 83 | * Limit the request by its Id. |
||
| 84 | * |
||
| 85 | * @param IQueryBuilder $qb |
||
| 86 | * @param int $id |
||
| 87 | */ |
||
| 88 | protected function limitToId(IQueryBuilder & $qb, $id) { |
||
| 94 | |||
| 95 | |||
| 96 | /** |
||
| 97 | * Limit the request by its UniqueId. |
||
| 98 | * |
||
| 99 | * @param IQueryBuilder $qb |
||
| 100 | * @param int $uniqueId |
||
| 101 | */ |
||
| 102 | protected function limitToUniqueId(IQueryBuilder & $qb, $uniqueId) { |
||
| 108 | |||
| 109 | |||
| 110 | /** |
||
| 111 | * Limit the request by its Token. |
||
| 112 | * |
||
| 113 | * @param IQueryBuilder $qb |
||
| 114 | * @param string $token |
||
| 115 | */ |
||
| 116 | protected function limitToToken(IQueryBuilder & $qb, $token) { |
||
| 122 | |||
| 123 | |||
| 124 | /** |
||
| 125 | * Limit the request to a minimum member level. |
||
| 126 | * |
||
| 127 | * @param IQueryBuilder $qb |
||
| 128 | * @param integer $level |
||
| 129 | */ |
||
| 130 | protected function limitToMemberLevel(IQueryBuilder & $qb, $level) { |
||
| 136 | |||
| 137 | |||
| 138 | /** |
||
| 139 | * add a request to the members list, using the current user ID. |
||
| 140 | * will returns level and stuff. |
||
| 141 | * |
||
| 142 | * @param IQueryBuilder $qb |
||
| 143 | * @param string $userId |
||
| 144 | */ |
||
| 145 | protected function leftJoinUserIdAsMember(IQueryBuilder & $qb, $userId) { |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @param IQueryBuilder $qb |
||
| 166 | * |
||
| 167 | * @deprecated |
||
| 168 | * never used in fact. |
||
| 169 | */ |
||
| 170 | protected function leftJoinOwner(IQueryBuilder & $qb) { |
||
| 187 | |||
| 188 | |||
| 189 | /** |
||
| 190 | * Base of the Sql Select request for Shares |
||
| 191 | * |
||
| 192 | * @return IQueryBuilder |
||
| 193 | */ |
||
| 194 | protected function getLinksSelectSql() { |
||
| 204 | |||
| 205 | |||
| 206 | /** |
||
| 207 | * Base of the Sql Select request for Shares |
||
| 208 | * |
||
| 209 | * @return IQueryBuilder |
||
| 210 | */ |
||
| 211 | protected function getSharesSelectSql() { |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Base of the Sql Insert request for Shares |
||
| 227 | * |
||
| 228 | * @return IQueryBuilder |
||
| 229 | */ |
||
| 230 | protected function getSharesInsertSql() { |
||
| 237 | |||
| 238 | |||
| 239 | /** |
||
| 240 | * Base of the Sql Update request for Shares |
||
| 241 | * |
||
| 242 | * @param string $uniqueId |
||
| 243 | * |
||
| 244 | * @return IQueryBuilder |
||
| 245 | */ |
||
| 246 | protected function getSharesUpdateSql($uniqueId) { |
||
| 256 | |||
| 257 | |||
| 258 | /** |
||
| 259 | * @return IQueryBuilder |
||
| 260 | */ |
||
| 261 | protected function getMembersSelectSql() { |
||
| 271 | |||
| 272 | |||
| 273 | /** |
||
| 274 | * @return IQueryBuilder |
||
| 275 | */ |
||
| 276 | protected function getCirclesSelectSql() { |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @param array $data |
||
| 288 | * |
||
| 289 | * @return Member |
||
| 290 | */ |
||
| 291 | protected function parseMembersSelectSql(array $data) { |
||
| 301 | |||
| 302 | |||
| 303 | /** |
||
| 304 | * @param array $data |
||
| 305 | * |
||
| 306 | * @return Circle |
||
| 307 | */ |
||
| 308 | protected function parseCirclesSelectSql($data) { |
||
| 330 | |||
| 331 | |||
| 332 | /** |
||
| 333 | * @param array $data |
||
| 334 | * |
||
| 335 | * @return SharingFrame |
||
| 336 | */ |
||
| 337 | protected function parseSharesSelectSql($data) { |
||
| 353 | |||
| 354 | |||
| 355 | /** |
||
| 356 | * @param array $data |
||
| 357 | * |
||
| 358 | * @return FederatedLink |
||
| 359 | */ |
||
| 360 | View Code Duplication | public function parseLinksSelectSql($data) { |
|
| 375 | |||
| 376 | |||
| 377 | } |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.