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 SharingFrameService { |
||
| 49 | |||
| 50 | /** @var string */ |
||
| 51 | private $userId; |
||
| 52 | |||
| 53 | /** @var ConfigService */ |
||
| 54 | private $configService; |
||
| 55 | |||
| 56 | /** @var CirclesRequest */ |
||
| 57 | private $circlesRequest; |
||
| 58 | |||
| 59 | /** @var FederatedLinksRequest */ |
||
| 60 | private $federatedLinksRequest; |
||
| 61 | |||
| 62 | /** @var BroadcastService */ |
||
| 63 | private $broadcastService; |
||
| 64 | |||
| 65 | /** @var FederatedLinkService */ |
||
| 66 | private $federatedLinkService; |
||
| 67 | |||
| 68 | /** @var ClientService */ |
||
| 69 | private $clientService; |
||
| 70 | |||
| 71 | /** @var MiscService */ |
||
| 72 | private $miscService; |
||
| 73 | |||
| 74 | |||
| 75 | /** |
||
| 76 | * SharingFrameService constructor. |
||
| 77 | * |
||
| 78 | * @param string $UserId |
||
| 79 | * @param ConfigService $configService |
||
| 80 | * @param CirclesRequest $circlesRequest |
||
| 81 | * @param FederatedLinksRequest $federatedLinksRequest |
||
| 82 | * @param BroadcastService $broadcastService |
||
| 83 | * @param FederatedLinkService $federatedLinkService |
||
| 84 | * @param IClientService $clientService |
||
| 85 | * @param MiscService $miscService |
||
| 86 | */ |
||
| 87 | public function __construct( |
||
|
|
|||
| 88 | $UserId, |
||
| 89 | ConfigService $configService, |
||
| 90 | CirclesRequest $circlesRequest, |
||
| 91 | FederatedLinksRequest $federatedLinksRequest, |
||
| 92 | BroadcastService $broadcastService, |
||
| 93 | FederatedLinkService $federatedLinkService, |
||
| 94 | IClientService $clientService, |
||
| 95 | MiscService $miscService |
||
| 96 | ) { |
||
| 97 | $this->userId = $UserId; |
||
| 98 | $this->configService = $configService; |
||
| 99 | $this->circlesRequest = $circlesRequest; |
||
| 100 | $this->federatedLinksRequest = $federatedLinksRequest; |
||
| 101 | $this->broadcastService = $broadcastService; |
||
| 102 | $this->federatedLinkService = $federatedLinkService; |
||
| 103 | $this->clientService = $clientService; |
||
| 104 | $this->miscService = $miscService; |
||
| 105 | } |
||
| 106 | |||
| 107 | |||
| 108 | /** |
||
| 109 | * createFrame() |
||
| 110 | * |
||
| 111 | * Save the Frame containing the Payload. |
||
| 112 | * The Payload will be shared locally, and spread it live if a Broadcaster is set. |
||
| 113 | * Function will also initiate the federated broadcast to linked circles. |
||
| 114 | * |
||
| 115 | * @param string $circleUniqueId |
||
| 116 | * @param SharingFrame $frame |
||
| 117 | * @param string|null $broadcast |
||
| 118 | * |
||
| 119 | * @throws Exception |
||
| 120 | * @throws MemberDoesNotExistException |
||
| 121 | */ |
||
| 122 | View Code Duplication | public function createFrame($circleUniqueId, SharingFrame $frame, $broadcast = null) { |
|
| 139 | |||
| 140 | |||
| 141 | /** |
||
| 142 | * Generate Headers and few more thing like UniqueId and Author. |
||
| 143 | * Check if the source is NOT Circles. |
||
| 144 | * |
||
| 145 | * @param SharingFrame $frame |
||
| 146 | * @param Circle $circle |
||
| 147 | * @param $broadcast |
||
| 148 | */ |
||
| 149 | private function generateHeaders(SharingFrame $frame, Circle $circle, $broadcast) { |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @param string $circleUniqueId |
||
| 168 | * @param string $frameUniqueId |
||
| 169 | * |
||
| 170 | * @return null|SharingFrame |
||
| 171 | * @throws SharingFrameAlreadyDeliveredException |
||
| 172 | * @throws SharingFrameDoesNotExistException |
||
| 173 | */ |
||
| 174 | public function getFrameFromUniqueId($circleUniqueId, $frameUniqueId) { |
||
| 190 | |||
| 191 | |||
| 192 | /** |
||
| 193 | * @param string $token |
||
| 194 | * @param string $uniqueId |
||
| 195 | * @param SharingFrame $frame |
||
| 196 | * |
||
| 197 | * @return bool |
||
| 198 | * @throws Exception |
||
| 199 | */ |
||
| 200 | public function receiveFrame($token, $uniqueId, SharingFrame &$frame) { |
||
| 221 | |||
| 222 | |||
| 223 | /** |
||
| 224 | * @param string $circleUniqueId |
||
| 225 | * @param string $frameUniqueId |
||
| 226 | * |
||
| 227 | * @return bool |
||
| 228 | * @throws Exception |
||
| 229 | */ |
||
| 230 | public function initiateShare($circleUniqueId, $frameUniqueId) { |
||
| 251 | |||
| 252 | |||
| 253 | /** |
||
| 254 | * @param string $remote |
||
| 255 | * |
||
| 256 | * @return string |
||
| 257 | */ |
||
| 258 | private function generatePayloadDeliveryURL($remote) { |
||
| 261 | |||
| 262 | |||
| 263 | /** |
||
| 264 | * @param SharingFrame $frame |
||
| 265 | * |
||
| 266 | * @throws Exception |
||
| 267 | */ |
||
| 268 | public function forwardSharingFrame(SharingFrame $frame) { |
||
| 286 | |||
| 287 | |||
| 288 | /** |
||
| 289 | * @param Circle $circle |
||
| 290 | * @param SharingFrame $frame |
||
| 291 | * @param FederatedLink[] $links |
||
| 292 | */ |
||
| 293 | private function forwardSharingFrameToFederatedLinks(Circle $circle, SharingFrame $frame, $links) { |
||
| 306 | |||
| 307 | |||
| 308 | /** |
||
| 309 | * sendRemoteShareToLinks(); |
||
| 310 | * |
||
| 311 | * @param FederatedLink $link |
||
| 312 | * @param array $args |
||
| 313 | */ |
||
| 314 | private function deliverSharingFrameToLink($link, $args) { |
||
| 337 | |||
| 338 | |||
| 339 | /** |
||
| 340 | * @param SharingFrame $frame |
||
| 341 | */ |
||
| 342 | public function updateFrameWithCloudId(SharingFrame $frame) { |
||
| 346 | |||
| 347 | |||
| 348 | } |
This check marks parameter names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.