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 |
||
| 45 | class FederatedService { |
||
| 46 | |||
| 47 | |||
| 48 | /** @var string */ |
||
| 49 | private $userId; |
||
| 50 | |||
| 51 | /** @var IL10N */ |
||
| 52 | private $l10n; |
||
| 53 | |||
| 54 | /** @var CirclesRequest */ |
||
| 55 | private $circlesRequest; |
||
| 56 | |||
| 57 | /** @var ConfigService */ |
||
| 58 | private $configService; |
||
| 59 | |||
| 60 | /** @var CirclesService */ |
||
| 61 | private $circlesService; |
||
| 62 | |||
| 63 | /** @var SharesService */ |
||
| 64 | private $sharesService; |
||
|
|
|||
| 65 | |||
| 66 | /** @var FederatedLinksRequest */ |
||
| 67 | private $federatedLinksRequest; |
||
| 68 | |||
| 69 | /** @var string */ |
||
| 70 | private $serverHost; |
||
| 71 | |||
| 72 | /** @var ClientService */ |
||
| 73 | private $clientService; |
||
| 74 | |||
| 75 | /** @var MiscService */ |
||
| 76 | private $miscService; |
||
| 77 | |||
| 78 | |||
| 79 | /** |
||
| 80 | * CirclesService constructor. |
||
| 81 | * |
||
| 82 | * @param $userId |
||
| 83 | * @param IL10N $l10n |
||
| 84 | * @param CirclesRequest $circlesRequest |
||
| 85 | * @param ConfigService $configService |
||
| 86 | * @param DatabaseService $databaseService |
||
| 87 | * @param CirclesService $circlesService |
||
| 88 | * @param SharesService $sharesService |
||
| 89 | * @param FederatedLinksRequest $federatedLinksRequest |
||
| 90 | * @param string $serverHost |
||
| 91 | * @param ClientService $clientService |
||
| 92 | * @param MiscService $miscService |
||
| 93 | */ |
||
| 94 | View Code Duplication | public function __construct( |
|
| 117 | |||
| 118 | |||
| 119 | /** |
||
| 120 | * linkCircle() |
||
| 121 | * |
||
| 122 | * link to a circle. |
||
| 123 | * Function will check if settings allow Federated links between circles, and the format of |
||
| 124 | * the link ($remote). If no exception, a request to the remote circle will be initiated |
||
| 125 | * using requestLinkWithCircle() |
||
| 126 | * |
||
| 127 | * $remote format: <circle_name>@<remote_host> |
||
| 128 | * |
||
| 129 | * @param int $circleId |
||
| 130 | * @param string $remote |
||
| 131 | * |
||
| 132 | * @throws Exception |
||
| 133 | * @throws FederatedCircleLinkFormatException |
||
| 134 | * @throws CircleTypeNotValid |
||
| 135 | * @throws MemberIsNotAdminException |
||
| 136 | * |
||
| 137 | * @return FederatedLink |
||
| 138 | */ |
||
| 139 | public function linkCircle($circleId, $remote) { |
||
| 159 | |||
| 160 | |||
| 161 | /** |
||
| 162 | * requestLinkWithCircle() |
||
| 163 | * |
||
| 164 | * Using CircleId, function will get more infos from the database. |
||
| 165 | * Will check if author is not admin and initiate a FederatedLink, save it |
||
| 166 | * in the database and send a request to the remote circle using requestLink() |
||
| 167 | * If any issue, entry is removed from the database. |
||
| 168 | * |
||
| 169 | * @param $circleId |
||
| 170 | * @param $remote |
||
| 171 | * |
||
| 172 | * @return FederatedLink |
||
| 173 | * @throws Exception |
||
| 174 | */ |
||
| 175 | private function requestLinkWithCircle($circleId, $remote) { |
||
| 204 | |||
| 205 | |||
| 206 | /** |
||
| 207 | * @param string $remote |
||
| 208 | * |
||
| 209 | * @return string |
||
| 210 | */ |
||
| 211 | View Code Duplication | private function generateLinkRemoteURL($remote) { |
|
| 218 | |||
| 219 | /** |
||
| 220 | * @param string $remote |
||
| 221 | * |
||
| 222 | * @return string |
||
| 223 | */ |
||
| 224 | View Code Duplication | private function generatePayloadDeliveryURL($remote) { |
|
| 231 | |||
| 232 | |||
| 233 | /** |
||
| 234 | * requestLink() |
||
| 235 | * |
||
| 236 | * |
||
| 237 | * @param Circle $circle |
||
| 238 | * @param FederatedLink $link |
||
| 239 | * |
||
| 240 | * @return int |
||
| 241 | * @throws Exception |
||
| 242 | */ |
||
| 243 | private function requestLink(Circle $circle, FederatedLink &$link) { |
||
| 278 | |||
| 279 | |||
| 280 | private function parsingRequestLinkResult($result) { |
||
| 308 | |||
| 309 | |||
| 310 | /** |
||
| 311 | * Create a new link into database and assign the correct status. |
||
| 312 | * |
||
| 313 | * @param Circle $circle |
||
| 314 | * @param FederatedLink $link |
||
| 315 | * |
||
| 316 | * @return bool |
||
| 317 | */ |
||
| 318 | public function initiateLink(Circle $circle, FederatedLink &$link) { |
||
| 330 | |||
| 331 | |||
| 332 | /** |
||
| 333 | * @param string $token |
||
| 334 | * @param string $uniqueId |
||
| 335 | * @param SharingFrame $frame |
||
| 336 | * |
||
| 337 | * @return bool |
||
| 338 | */ |
||
| 339 | public function receiveFrame(string $token, string $uniqueId, SharingFrame $frame) { |
||
| 366 | |||
| 367 | /** |
||
| 368 | * @param $circleId |
||
| 369 | * @param $uniqueId |
||
| 370 | * |
||
| 371 | * @return FederatedLink |
||
| 372 | */ |
||
| 373 | public function getLink($circleId, $uniqueId) { |
||
| 376 | |||
| 377 | |||
| 378 | /** |
||
| 379 | * @param $circleId |
||
| 380 | * |
||
| 381 | * @return FederatedLink[] |
||
| 382 | */ |
||
| 383 | public function getLinks($circleId) { |
||
| 386 | |||
| 387 | |||
| 388 | /** |
||
| 389 | * @param int $circleId |
||
| 390 | * @param string $uniqueId |
||
| 391 | * |
||
| 392 | * @return bool |
||
| 393 | * @throws Exception |
||
| 394 | */ |
||
| 395 | public function initiateRemoteShare(int $circleId, string $uniqueId) { |
||
| 421 | |||
| 422 | |||
| 423 | /** |
||
| 424 | * @param SharingFrame $frame |
||
| 425 | * |
||
| 426 | * @throws Exception |
||
| 427 | */ |
||
| 428 | public function sendRemoteShare(SharingFrame $frame) { |
||
| 458 | |||
| 459 | |||
| 460 | /** |
||
| 461 | * generateHeaders() |
||
| 462 | * |
||
| 463 | * Generate new headers for the current Payload, and save them in the SharingFrame. |
||
| 464 | * |
||
| 465 | * @param SharingFrame $frame |
||
| 466 | */ |
||
| 467 | public function updateFrameWithCloudId(SharingFrame $frame) { |
||
| 471 | |||
| 472 | } |
This check marks private properties in classes that are never used. Those properties can be removed.