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 |
||
| 42 | class CirclesRequestBuilder extends CoreRequestBuilder { |
||
| 43 | |||
| 44 | |||
| 45 | /** @var MembersRequest */ |
||
| 46 | protected $membersRequest; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * CirclesRequestBuilder constructor. |
||
| 50 | * |
||
| 51 | * {@inheritdoc} |
||
| 52 | * @param MembersRequest $membersRequest |
||
| 53 | */ |
||
| 54 | public function __construct( |
||
| 61 | |||
| 62 | |||
| 63 | /** |
||
| 64 | * Left Join the Groups table |
||
| 65 | * |
||
| 66 | * @param IQueryBuilder $qb |
||
| 67 | * @param string $field |
||
| 68 | */ |
||
| 69 | protected function leftJoinGroups(& $qb, $field) { |
||
| 77 | |||
| 78 | // |
||
| 79 | // /** |
||
| 80 | // * Link to member (userId) of circle |
||
| 81 | // * |
||
| 82 | // * @param IQueryBuilder $qb |
||
| 83 | // * @param string $field |
||
| 84 | // */ |
||
| 85 | // protected function leftJoinMembers(& $qb, $field) { |
||
| 86 | // $expr = $qb->expr(); |
||
| 87 | // |
||
| 88 | // $qb->leftJoin( |
||
| 89 | // $this->default_select_alias, CoreRequestBuilder::TABLE_MEMBERS, 'm', |
||
| 90 | // $expr->eq('m.circle_id', $field) |
||
| 91 | // ); |
||
| 92 | //// $qb->from(self::TABLE_MEMBERS, 'm') |
||
| 93 | //// ->andWhere($expr->eq('m.circle_id', $field)); |
||
| 94 | // } |
||
| 95 | |||
| 96 | |||
| 97 | /** |
||
| 98 | * Limit the search to a non-personal circle |
||
| 99 | * |
||
| 100 | * @param IQueryBuilder $qb |
||
| 101 | */ |
||
| 102 | protected function limitToNonPersonalCircle(IQueryBuilder &$qb) { |
||
| 109 | |||
| 110 | |||
| 111 | /** |
||
| 112 | * @param IQueryBuilder $qb |
||
| 113 | * @param $circleId |
||
| 114 | * @param $userId |
||
| 115 | * @param $type |
||
| 116 | * @param $name |
||
| 117 | * |
||
| 118 | * @throws ConfigNoCircleAvailable |
||
| 119 | */ |
||
| 120 | protected function limitRegardingCircleType(IQueryBuilder &$qb, $userId, $circleId, $type, $name |
||
| 139 | |||
| 140 | |||
| 141 | /** |
||
| 142 | * @param IQueryBuilder $qb |
||
| 143 | * @param $circleId |
||
| 144 | * @param $userId |
||
| 145 | * @param $type |
||
| 146 | * @param $name |
||
| 147 | * |
||
| 148 | * @return array |
||
| 149 | */ |
||
| 150 | private function generateLimit(IQueryBuilder &$qb, $circleId, $userId, $type, $name) { |
||
| 159 | |||
| 160 | |||
| 161 | /** |
||
| 162 | * @param IQueryBuilder $qb |
||
| 163 | * @param int|string $userId |
||
| 164 | * @param int $type |
||
| 165 | * |
||
| 166 | * @return \OCP\DB\QueryBuilder\ICompositeExpression |
||
| 167 | */ |
||
| 168 | private function generateLimitPersonal(IQueryBuilder $qb, $userId, $type) { |
||
| 180 | |||
| 181 | |||
| 182 | /** |
||
| 183 | * @param IQueryBuilder $qb |
||
| 184 | * @param int $circleId |
||
| 185 | * @param int $type |
||
| 186 | * @param string $name |
||
| 187 | * |
||
| 188 | * @return string |
||
| 189 | */ |
||
| 190 | private function generateLimitHidden(IQueryBuilder $qb, $circleId, $type, $name) { |
||
| 214 | |||
| 215 | |||
| 216 | /** |
||
| 217 | * @param IQueryBuilder $qb |
||
| 218 | * @param int $type |
||
| 219 | * |
||
| 220 | * @return string |
||
| 221 | */ |
||
| 222 | View Code Duplication | private function generateLimitPrivate(IQueryBuilder $qb, $type) { |
|
| 233 | |||
| 234 | |||
| 235 | /** |
||
| 236 | * @param IQueryBuilder $qb |
||
| 237 | * @param int $type |
||
| 238 | * |
||
| 239 | * @return string |
||
| 240 | */ |
||
| 241 | View Code Duplication | private function generateLimitPublic(IQueryBuilder $qb, $type) { |
|
| 252 | |||
| 253 | |||
| 254 | /** |
||
| 255 | * add a request to the members list, using the current user ID. |
||
| 256 | * will returns level and stuff. |
||
| 257 | * |
||
| 258 | * @param IQueryBuilder $qb |
||
| 259 | * @param string $userId |
||
| 260 | */ |
||
| 261 | View Code Duplication | protected function leftJoinUserIdAsViewer(IQueryBuilder & $qb, $userId) { |
|
| 282 | |||
| 283 | /** |
||
| 284 | * Left Join members table to get the owner of the circle. |
||
| 285 | * |
||
| 286 | * @param IQueryBuilder $qb |
||
| 287 | */ |
||
| 288 | View Code Duplication | protected function leftJoinOwner(IQueryBuilder & $qb) { |
|
| 309 | |||
| 310 | |||
| 311 | /** |
||
| 312 | * Base of the Sql Select request for Shares |
||
| 313 | * |
||
| 314 | * @return IQueryBuilder |
||
| 315 | */ |
||
| 316 | View Code Duplication | protected function getLinksSelectSql() { |
|
| 327 | |||
| 328 | |||
| 329 | /** |
||
| 330 | * Base of the Sql Select request for Shares |
||
| 331 | * |
||
| 332 | * @return IQueryBuilder |
||
| 333 | */ |
||
| 334 | View Code Duplication | protected function getSharesSelectSql() { |
|
| 348 | |||
| 349 | /** |
||
| 350 | * Base of the Sql Insert request for Shares |
||
| 351 | * |
||
| 352 | * @return IQueryBuilder |
||
| 353 | */ |
||
| 354 | View Code Duplication | protected function getSharesInsertSql() { |
|
| 361 | |||
| 362 | |||
| 363 | /** |
||
| 364 | * Base of the Sql Update request for Shares |
||
| 365 | * |
||
| 366 | * @param string $uniqueId |
||
| 367 | * |
||
| 368 | * @return IQueryBuilder |
||
| 369 | */ |
||
| 370 | View Code Duplication | protected function getSharesUpdateSql($uniqueId) { |
|
| 380 | |||
| 381 | |||
| 382 | /** |
||
| 383 | * Base of the Sql Insert request for Shares |
||
| 384 | * |
||
| 385 | * |
||
| 386 | * @return IQueryBuilder |
||
| 387 | */ |
||
| 388 | View Code Duplication | protected function getCirclesInsertSql() { |
|
| 395 | |||
| 396 | |||
| 397 | /** |
||
| 398 | * Base of the Sql Update request for Shares |
||
| 399 | * |
||
| 400 | * @param int $circleId |
||
| 401 | * |
||
| 402 | * @return IQueryBuilder |
||
| 403 | */ |
||
| 404 | protected function getCirclesUpdateSql($circleId) { |
||
| 414 | |||
| 415 | |||
| 416 | /** |
||
| 417 | * Base of the Sql Delete request |
||
| 418 | * |
||
| 419 | * @return IQueryBuilder |
||
| 420 | */ |
||
| 421 | protected function getCirclesDeleteSql() { |
||
| 427 | |||
| 428 | |||
| 429 | /** |
||
| 430 | * @return IQueryBuilder |
||
| 431 | */ |
||
| 432 | protected function getCirclesSelectSql() { |
||
| 446 | |||
| 447 | |||
| 448 | /** |
||
| 449 | * @param array $data |
||
| 450 | * |
||
| 451 | * @return Circle |
||
| 452 | */ |
||
| 453 | protected function parseCirclesSelectSql($data) { |
||
| 484 | |||
| 485 | |||
| 486 | /** |
||
| 487 | * @param array $data |
||
| 488 | * |
||
| 489 | * @return SharingFrame |
||
| 490 | */ |
||
| 491 | protected function parseSharesSelectSql($data) { |
||
| 503 | |||
| 504 | |||
| 505 | /** |
||
| 506 | * @param array $data |
||
| 507 | * |
||
| 508 | * @return FederatedLink |
||
| 509 | */ |
||
| 510 | protected function parseLinksSelectSql($data) { |
||
| 522 | |||
| 523 | |||
| 524 | } |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.