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 |
||
| 48 | class Circles { |
||
| 49 | |||
| 50 | const API_VERSION = [0, 10, 0]; |
||
| 51 | |||
| 52 | // Expose circle and member constants via API |
||
| 53 | const CIRCLES_PERSONAL = DeprecatedCircle::CIRCLES_PERSONAL; |
||
| 54 | const CIRCLES_SECRET = DeprecatedCircle::CIRCLES_SECRET; |
||
| 55 | const CIRCLES_CLOSED = DeprecatedCircle::CIRCLES_CLOSED; |
||
| 56 | const CIRCLES_PUBLIC = DeprecatedCircle::CIRCLES_PUBLIC; |
||
| 57 | const CIRCLES_ALL = DeprecatedCircle::CIRCLES_ALL; |
||
| 58 | |||
| 59 | const TYPE_USER = DeprecatedMember::TYPE_USER; |
||
| 60 | const TYPE_GROUP = DeprecatedMember::TYPE_GROUP; |
||
| 61 | const TYPE_MAIL = DeprecatedMember::TYPE_MAIL; |
||
| 62 | const TYPE_CONTACT = DeprecatedMember::TYPE_CONTACT; |
||
| 63 | |||
| 64 | const LEVEL_NONE = DeprecatedMember::LEVEL_NONE; |
||
| 65 | const LEVEL_MEMBER = DeprecatedMember::LEVEL_MEMBER; |
||
| 66 | const LEVEL_MODERATOR = DeprecatedMember::LEVEL_MODERATOR; |
||
| 67 | const LEVEL_ADMIN = DeprecatedMember::LEVEL_ADMIN; |
||
| 68 | const LEVEL_OWNER = DeprecatedMember::LEVEL_OWNER; |
||
| 69 | |||
| 70 | |||
| 71 | /** |
||
| 72 | * Circles::listCircles(); |
||
| 73 | * |
||
| 74 | * This function list all circles fitting a search regarding its name and the level and the |
||
| 75 | * rights from the current user. In case of Secret circle, name needs to be complete so the |
||
| 76 | * circle is included in the list (or if the current user is the owner) |
||
| 77 | * |
||
| 78 | * example: Circles::listCircles(Circles::CIRCLES_ALL, '', 8, callback); will returns all |
||
| 79 | * circles when the current user is at least an Admin. |
||
| 80 | * |
||
| 81 | * @param mixed $type |
||
| 82 | * @param string $name |
||
| 83 | * @param int $level |
||
| 84 | * @param string $userId |
||
| 85 | * @param bool $forceAll |
||
| 86 | * |
||
| 87 | * @return Circle[] |
||
| 88 | */ |
||
| 89 | View Code Duplication | public static function listCircles($type, $name = '', $level = 0, $userId = '', $forceAll = false) { |
|
| 114 | |||
| 115 | |||
| 116 | /** |
||
| 117 | * @param string $userId |
||
| 118 | * @param bool $forceAll |
||
| 119 | * |
||
| 120 | * @return Circle[] |
||
| 121 | * @throws FederatedUserException |
||
| 122 | * @throws FederatedUserNotFoundException |
||
| 123 | * @throws InitiatorNotFoundException |
||
| 124 | * @throws InvalidIdException |
||
| 125 | * @throws RequestBuilderException |
||
| 126 | * @throws SingleCircleNotFoundException |
||
| 127 | * |
||
| 128 | * @deprecated - used by apps/dav/lib/Connector/Sabre/Principal.php |
||
| 129 | * |
||
| 130 | * Circles::joinedCircles(); |
||
| 131 | * |
||
| 132 | * Return all the circle the current user is a member. |
||
| 133 | */ |
||
| 134 | View Code Duplication | public static function joinedCircles($userId = '', $forceAll = false) { |
|
| 163 | |||
| 164 | |||
| 165 | /** |
||
| 166 | * @param string $circleUniqueId |
||
| 167 | * @param bool $forceAll |
||
| 168 | * |
||
| 169 | * @return Circle |
||
| 170 | * @throws CircleNotFoundException |
||
| 171 | * @throws FederatedUserException |
||
| 172 | * @throws FederatedUserNotFoundException |
||
| 173 | * @throws InitiatorNotFoundException |
||
| 174 | * @throws InvalidIdException |
||
| 175 | * @throws RequestBuilderException |
||
| 176 | * @throws SingleCircleNotFoundException |
||
| 177 | * |
||
| 178 | * @deprecated - used by apps/dav/lib/Connector/Sabre/Principal.php |
||
| 179 | * - used by apps/files_sharing/lib/Controller/ShareAPIController.php |
||
| 180 | * - used by lib/private/Share20/Manager.php |
||
| 181 | * |
||
| 182 | * Circles::detailsCircle(); |
||
| 183 | * |
||
| 184 | * WARNING - This function is called by the core - WARNING |
||
| 185 | * Do not change it |
||
| 186 | * |
||
| 187 | * Returns details on the circle. If the current user is a member, the members list will be |
||
| 188 | * return as well. |
||
| 189 | * |
||
| 190 | */ |
||
| 191 | public static function detailsCircle(string $circleUniqueId, bool $forceAll = false): Circle { |
||
| 205 | |||
| 206 | |||
| 207 | /** |
||
| 208 | * @param string $circleUniqueId |
||
| 209 | * @param string $ident |
||
| 210 | * @param int $type |
||
| 211 | * @param bool $forceAll |
||
| 212 | * |
||
| 213 | * @return Member |
||
| 214 | * |
||
| 215 | * @deprecated - used by apps/files_sharing/lib/Controller/ShareAPIController.php |
||
| 216 | * |
||
| 217 | * Circles::getMember(); |
||
| 218 | * |
||
| 219 | * This function will return information on a member of the circle. Current user need at least |
||
| 220 | * to be Member. |
||
| 221 | * |
||
| 222 | */ |
||
| 223 | public static function getMember($circleUniqueId, $ident, $type, $forceAll = false) { |
||
| 229 | |||
| 230 | |||
| 231 | /** |
||
| 232 | * @param array $circleUniqueIds |
||
| 233 | * |
||
| 234 | * @return string[] array of object ids or empty array if none found |
||
| 235 | * |
||
| 236 | * @deprecated - used by apps/dav/lib/Connector/Sabre/FilesReportPlugin.php |
||
| 237 | * |
||
| 238 | * Get a list of objects which are shred with $circleUniqueId. |
||
| 239 | * |
||
| 240 | * @since 0.14.0 |
||
| 241 | * |
||
| 242 | */ |
||
| 243 | public static function getFilesForCircles($circleUniqueIds) { |
||
| 249 | |||
| 250 | } |
||
| 251 | |||
| 252 |
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.