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 |
||
| 41 | class DeprecatedMembersRequestBuilder extends DeprecatedRequestBuilder { |
||
| 42 | |||
| 43 | |||
| 44 | /** @var IGroupManager */ |
||
| 45 | protected $groupManager; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * CirclesRequestBuilder constructor. |
||
| 49 | * |
||
| 50 | * {@inheritdoc} |
||
| 51 | * @param IGroupManager $groupManager |
||
| 52 | */ |
||
| 53 | public function __construct( |
||
| 60 | |||
| 61 | |||
| 62 | /** |
||
| 63 | * Base of the Sql Insert request for Shares |
||
| 64 | * |
||
| 65 | * @return IQueryBuilder |
||
| 66 | */ |
||
| 67 | View Code Duplication | protected function getMembersInsertSql() { |
|
| 74 | |||
| 75 | |||
| 76 | /** |
||
| 77 | * @return IQueryBuilder |
||
| 78 | */ |
||
| 79 | View Code Duplication | protected function getMembersSelectSql() { |
|
| 80 | $qb = $this->dbConnection->getQueryBuilder(); |
||
| 81 | |||
| 82 | /** @noinspection PhpMethodParametersCountMismatchInspection */ |
||
| 83 | $qb->select( |
||
| 84 | 'm.user_id', 'm.instance', 'm.user_type', 'm.circle_id', 'm.level', 'm.status', 'm.note', |
||
| 85 | 'm.contact_id', 'm.member_id', 'm.cached_name', 'm.cached_update', 'm.contact_meta', 'm.joined' |
||
| 86 | ) |
||
| 87 | ->from(self::TABLE_MEMBERS, 'm') |
||
| 88 | ->orderBy('m.joined'); |
||
| 89 | |||
| 90 | $this->default_select_alias = 'm'; |
||
| 91 | |||
| 92 | return $qb; |
||
| 93 | } |
||
| 94 | |||
| 95 | |||
| 96 | /** |
||
| 97 | * Base of the Sql Updte request for Members |
||
| 98 | * |
||
| 99 | * @param string /$circleId |
||
| 100 | * @param string $userId |
||
| 101 | * @param string $instance |
||
| 102 | * @param int $type |
||
| 103 | * |
||
| 104 | * @return IQueryBuilder |
||
| 105 | */ |
||
| 106 | protected function getMembersUpdateSql(string $circleId, string $userId, string $instance, int $type) { |
||
| 123 | |||
| 124 | |||
| 125 | /** |
||
| 126 | * Base of the Sql Delete request for Members |
||
| 127 | * |
||
| 128 | * @return IQueryBuilder |
||
| 129 | */ |
||
| 130 | protected function getMembersDeleteSql() { |
||
| 136 | |||
| 137 | |||
| 138 | /** |
||
| 139 | * @param array $data |
||
| 140 | * |
||
| 141 | * @return DeprecatedMember |
||
| 142 | */ |
||
| 143 | protected function parseMembersSelectSql(array $data) { |
||
| 166 | |||
| 167 | |||
| 168 | /** |
||
| 169 | * @param array $data |
||
| 170 | * |
||
| 171 | * @return DeprecatedMember |
||
| 172 | */ |
||
| 173 | protected function parseGroupsSelectSql(array $data) { |
||
| 191 | |||
| 192 | } |
||
| 193 |
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.