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 |
||
| 36 | class MembersRequest extends MembersRequestBuilder { |
||
| 37 | |||
| 38 | |||
| 39 | |||
| 40 | /** |
||
| 41 | * forceGetGroup(); |
||
| 42 | * |
||
| 43 | * returns group information as a member within a Circle. |
||
| 44 | * |
||
| 45 | * WARNING: This function does not filters data regarding the current user/viewer. |
||
| 46 | * In case of interaction with users, Please use getGroup() instead. |
||
| 47 | * |
||
| 48 | * @param int $circleId |
||
| 49 | * @param string $groupId |
||
| 50 | * |
||
| 51 | * @return Member |
||
|
|
|||
| 52 | * @throws MemberDoesNotExistException |
||
| 53 | */ |
||
| 54 | View Code Duplication | public function forceGetGroup($circleId, $groupId) { |
|
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | // TODO - returns data of a group from a Viewer POV |
||
| 75 | public function getGroup($circleId, $groupId, $viewer) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @param int $circleId |
||
| 82 | * @param Member $viewer |
||
| 83 | * |
||
| 84 | * @return Member[] |
||
| 85 | * @throws MemberDoesNotExistException |
||
| 86 | */ |
||
| 87 | public function getGroups($circleId, Member $viewer) { |
||
| 110 | |||
| 111 | |||
| 112 | /** |
||
| 113 | * Insert Member into database. |
||
| 114 | * |
||
| 115 | * @param Member $member |
||
| 116 | * |
||
| 117 | * @throws MemberAlreadyExistsException |
||
| 118 | */ |
||
| 119 | public function insertGroup(Member $member) { |
||
| 134 | |||
| 135 | |||
| 136 | /** |
||
| 137 | * update database entry for a specific Group. |
||
| 138 | * |
||
| 139 | * @param Member $member |
||
| 140 | * |
||
| 141 | * @return bool |
||
| 142 | */ |
||
| 143 | public function editGroup(Member $member) { |
||
| 151 | |||
| 152 | |||
| 153 | public function unlinkAllFromGroupId($groupId) |
||
| 158 | |||
| 159 | } |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.