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 |
||
| 38 | class FederatedLinksRequestBuilder extends CoreRequestBuilder { |
||
| 39 | |||
| 40 | |||
| 41 | /** |
||
| 42 | * CirclesRequestBuilder constructor. |
||
| 43 | * |
||
| 44 | * {@inheritdoc} |
||
| 45 | */ |
||
| 46 | public function __construct( |
||
| 47 | IL10N $l10n, IDBConnection $connection, ConfigService $configService, MiscService $miscService |
||
| 48 | ) { |
||
| 49 | parent::__construct($l10n, $connection, $configService, $miscService); |
||
| 50 | } |
||
| 51 | |||
| 52 | |||
| 53 | /** |
||
| 54 | * Base of the Sql Insert request |
||
| 55 | * |
||
| 56 | * @return IQueryBuilder |
||
| 57 | */ |
||
| 58 | View Code Duplication | protected function getLinksInsertSql() { |
|
|
|
|||
| 59 | $qb = $this->dbConnection->getQueryBuilder(); |
||
| 60 | $qb->insert(self::TABLE_LINKS) |
||
| 61 | ->setValue('creation', $qb->createFunction('NOW()')); |
||
| 62 | |||
| 63 | return $qb; |
||
| 64 | } |
||
| 65 | |||
| 66 | |||
| 67 | /** |
||
| 68 | * Base of the Sql Update request |
||
| 69 | * |
||
| 70 | * @return IQueryBuilder |
||
| 71 | */ |
||
| 72 | protected function getLinksUpdateSql() { |
||
| 73 | $qb = $this->dbConnection->getQueryBuilder(); |
||
| 74 | $qb->update(self::TABLE_LINKS); |
||
| 75 | |||
| 76 | return $qb; |
||
| 77 | } |
||
| 78 | |||
| 79 | |||
| 80 | /** |
||
| 81 | * Base of the Sql Select request for Shares |
||
| 82 | * |
||
| 83 | * @return IQueryBuilder |
||
| 84 | */ |
||
| 85 | protected function getLinksSelectSql() { |
||
| 86 | $qb = $this->dbConnection->getQueryBuilder(); |
||
| 87 | |||
| 88 | /** @noinspection PhpMethodParametersCountMismatchInspection */ |
||
| 89 | $qb->select( |
||
| 90 | 'l.id', 'l.status', 'l.address', 'l.token', 'l.circle_id', 'l.unique_id', 'l.creation' |
||
| 91 | ) |
||
| 92 | ->from(self::TABLE_LINKS, 'l'); |
||
| 93 | |||
| 94 | $this->default_select_alias = 'l'; |
||
| 95 | |||
| 96 | return $qb; |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Base of the Sql Delete request |
||
| 101 | * |
||
| 102 | * @return IQueryBuilder |
||
| 103 | */ |
||
| 104 | protected function getLinksDeleteSql() { |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @param array $data |
||
| 113 | * |
||
| 114 | * @return FederatedLink |
||
| 115 | */ |
||
| 116 | protected function parseLinksSelectSql($data) { |
||
| 128 | |||
| 129 | } |
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.