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 $broadcastService; |
||
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 BroadcastService $broadcastService |
||
89 | * @param FederatedLinksRequest $federatedLinksRequest |
||
90 | * @param string $serverHost |
||
91 | * @param ClientService $clientService |
||
92 | * @param MiscService $miscService |
||
93 | */ |
||
94 | public function __construct( |
||
118 | |||
119 | |||
120 | /** |
||
121 | * linkCircle() |
||
122 | * |
||
123 | * link to a circle. |
||
124 | * Function will check if settings allow Federated links between circles, and the format of |
||
125 | * the link ($remote). If no exception, a request to the remote circle will be initiated |
||
126 | * using requestLinkWithCircle() |
||
127 | * |
||
128 | * $remote format: <circle_name>@<remote_host> |
||
129 | * |
||
130 | * @param int $circleId |
||
131 | * @param string $remote |
||
132 | * |
||
133 | * @throws Exception |
||
134 | * @throws FederatedCircleLinkFormatException |
||
135 | * @throws CircleTypeNotValid |
||
136 | * @throws MemberIsNotAdminException |
||
137 | * |
||
138 | * @return FederatedLink |
||
139 | */ |
||
140 | public function linkCircle($circleId, $remote) { |
||
160 | |||
161 | |||
162 | /** |
||
163 | * requestLinkWithCircle() |
||
164 | * |
||
165 | * Using CircleId, function will get more infos from the database. |
||
166 | * Will check if author is not admin and initiate a FederatedLink, save it |
||
167 | * in the database and send a request to the remote circle using requestLink() |
||
168 | * If any issue, entry is removed from the database. |
||
169 | * |
||
170 | * @param $circleId |
||
171 | * @param $remote |
||
172 | * |
||
173 | * @return FederatedLink |
||
174 | * @throws Exception |
||
175 | */ |
||
176 | private function requestLinkWithCircle($circleId, $remote) { |
||
205 | |||
206 | |||
207 | /** |
||
208 | * @param string $remote |
||
209 | * |
||
210 | * @return string |
||
211 | */ |
||
212 | View Code Duplication | private function generateLinkRemoteURL($remote) { |
|
219 | |||
220 | /** |
||
221 | * @param string $remote |
||
222 | * |
||
223 | * @return string |
||
224 | */ |
||
225 | View Code Duplication | private function generatePayloadDeliveryURL($remote) { |
|
232 | |||
233 | |||
234 | /** |
||
235 | * requestLink() |
||
236 | * |
||
237 | * |
||
238 | * @param Circle $circle |
||
239 | * @param FederatedLink $link |
||
240 | * |
||
241 | * @return int |
||
242 | * @throws Exception |
||
243 | */ |
||
244 | private function requestLink(Circle $circle, FederatedLink &$link) { |
||
279 | |||
280 | |||
281 | private function parsingRequestLinkResult($result) { |
||
309 | |||
310 | |||
311 | /** |
||
312 | * Create a new link into database and assign the correct status. |
||
313 | * |
||
314 | * @param Circle $circle |
||
315 | * @param FederatedLink $link |
||
316 | * |
||
317 | * @return bool |
||
318 | */ |
||
319 | public function initiateLink(Circle $circle, FederatedLink &$link) { |
||
331 | |||
332 | |||
333 | /** |
||
334 | * @param string $token |
||
335 | * @param string $uniqueId |
||
336 | * @param SharingFrame $frame |
||
337 | * |
||
338 | * @return bool |
||
339 | * @throws Exception |
||
340 | */ |
||
341 | public function receiveFrame(string $token, string $uniqueId, SharingFrame &$frame) { |
||
370 | |||
371 | /** |
||
372 | * @param $circleId |
||
373 | * @param $uniqueId |
||
374 | * |
||
375 | * @return FederatedLink |
||
376 | */ |
||
377 | public function getLink($circleId, $uniqueId) { |
||
380 | |||
381 | |||
382 | /** |
||
383 | * @param $circleId |
||
384 | * |
||
385 | * @return FederatedLink[] |
||
386 | */ |
||
387 | public function getLinks($circleId) { |
||
390 | |||
391 | |||
392 | /** |
||
393 | * @param int $circleId |
||
394 | * @param string $uniqueId |
||
395 | * |
||
396 | * @return bool |
||
397 | * @throws Exception |
||
398 | */ |
||
399 | public function initiateRemoteShare(int $circleId, string $uniqueId) { |
||
425 | |||
426 | |||
427 | /** |
||
428 | * @param SharingFrame $frame |
||
429 | * |
||
430 | * @throws Exception |
||
431 | */ |
||
432 | public function sendRemoteShare(SharingFrame $frame) { |
||
462 | |||
463 | |||
464 | /** |
||
465 | * generateHeaders() |
||
466 | * |
||
467 | * Generate new headers for the current Payload, and save them in the SharingFrame. |
||
468 | * |
||
469 | * @param SharingFrame $frame |
||
470 | */ |
||
471 | public function updateFrameWithCloudId(SharingFrame $frame) { |
||
475 | |||
476 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.