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 |
||
16 | class _Discussion extends AbstractResource |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * The resource endpoint |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $endpoint = '/discussions/categories'; |
||
25 | |||
26 | /** |
||
27 | * The forums resource endpoint |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | private $forumsEndpoint = '/discussions/forums'; |
||
|
|||
32 | |||
33 | /** |
||
34 | * The forums topics resource endpoint |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $topicsEndpoint = '/discussions/topics'; |
||
39 | |||
40 | |||
41 | |||
42 | /** |
||
43 | * Creates the forums endpoint |
||
44 | * @param null $id |
||
45 | * @return string |
||
46 | */ |
||
47 | protected function topicsEndpoint($id = null) |
||
51 | |||
52 | /** |
||
53 | * |
||
54 | * List forum categories. |
||
55 | * |
||
56 | * @param array $query |
||
57 | * @return array|null |
||
58 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
59 | * @throws \Freshdesk\Exceptions\ApiException |
||
60 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
61 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
62 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
63 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
64 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
65 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
66 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
67 | * @throws \Freshdesk\Exceptions\ValidationException |
||
68 | * @internal param $id |
||
69 | */ |
||
70 | public function allCategories(array $query = null) |
||
74 | |||
75 | /** |
||
76 | * |
||
77 | * Create a forum category. |
||
78 | * |
||
79 | * @param array $data |
||
80 | * @return array|null |
||
81 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
82 | * @throws \Freshdesk\Exceptions\ApiException |
||
83 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
84 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
85 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
86 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
87 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
88 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
89 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
90 | * @throws \Freshdesk\Exceptions\ValidationException |
||
91 | */ |
||
92 | public function createCategory(array $data) |
||
96 | |||
97 | /** |
||
98 | * |
||
99 | * View a forum category. |
||
100 | * |
||
101 | * @param int $id |
||
102 | * @return array|null |
||
103 | * @param array|null $query |
||
104 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
105 | * @throws \Freshdesk\Exceptions\ApiException |
||
106 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
107 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
108 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
109 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
110 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
111 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
112 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
113 | * @throws \Freshdesk\Exceptions\ValidationException |
||
114 | */ |
||
115 | public function viewCategory($id, array $query = null) |
||
119 | |||
120 | /** |
||
121 | * |
||
122 | * Update a forum category. |
||
123 | * |
||
124 | * @param int $id |
||
125 | * @param array $data |
||
126 | * @return array|null |
||
127 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
128 | * @throws \Freshdesk\Exceptions\ApiException |
||
129 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
130 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
131 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
132 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
133 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
134 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
135 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
136 | * @throws \Freshdesk\Exceptions\ValidationException |
||
137 | */ |
||
138 | public function updateCategory($id, array $data) |
||
142 | |||
143 | /** |
||
144 | * |
||
145 | * Delete a forum category. |
||
146 | * |
||
147 | * @param int $id |
||
148 | * @return array|null |
||
149 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
150 | * @throws \Freshdesk\Exceptions\ApiException |
||
151 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
152 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
153 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
154 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
155 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
156 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
157 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
158 | * @throws \Freshdesk\Exceptions\ValidationException |
||
159 | */ |
||
160 | public function deleteCategory($id) |
||
164 | |||
165 | /** |
||
166 | * |
||
167 | * Create a forum for a category. |
||
168 | * |
||
169 | * @param int $id The category Id |
||
170 | * @param array $data |
||
171 | * @return array|null |
||
172 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
173 | * @throws \Freshdesk\Exceptions\ApiException |
||
174 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
175 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
176 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
177 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
178 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
179 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
180 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
181 | * @throws \Freshdesk\Exceptions\ValidationException |
||
182 | */ |
||
183 | public function createForum($id, array $data) |
||
187 | |||
188 | /** |
||
189 | * |
||
190 | * View a forum |
||
191 | * |
||
192 | * @param int $id |
||
193 | * @param array|null $query |
||
194 | * @return array|null |
||
195 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
196 | * @throws \Freshdesk\Exceptions\ApiException |
||
197 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
198 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
199 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
200 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
201 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
202 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
203 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
204 | * @throws \Freshdesk\Exceptions\ValidationException |
||
205 | */ |
||
206 | public function viewForum($id, array $query = null) |
||
210 | |||
211 | /** |
||
212 | * |
||
213 | * Update a forum |
||
214 | * |
||
215 | * @param int $id |
||
216 | * @param array $data |
||
217 | * @return array|null |
||
218 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
219 | * @throws \Freshdesk\Exceptions\ApiException |
||
220 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
221 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
222 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
223 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
224 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
225 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
226 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
227 | * @throws \Freshdesk\Exceptions\ValidationException |
||
228 | */ |
||
229 | public function updateForum($id, array $data) |
||
233 | |||
234 | /** |
||
235 | * |
||
236 | * Update a forum |
||
237 | * |
||
238 | * @param int $id |
||
239 | * @return array|null |
||
240 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
241 | * @throws \Freshdesk\Exceptions\ApiException |
||
242 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
243 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
244 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
245 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
246 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
247 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
248 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
249 | * @throws \Freshdesk\Exceptions\ValidationException |
||
250 | */ |
||
251 | public function deleteForum($id) |
||
255 | |||
256 | /** |
||
257 | * |
||
258 | * Monitor a forum for the given user |
||
259 | * |
||
260 | * @param int $userId |
||
261 | * @return array|null |
||
262 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
263 | * @throws \Freshdesk\Exceptions\ApiException |
||
264 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
265 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
266 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
267 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
268 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
269 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
270 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
271 | * @throws \Freshdesk\Exceptions\ValidationException |
||
272 | */ |
||
273 | View Code Duplication | public function monitorForum($id, $userId) |
|
281 | |||
282 | /** |
||
283 | * |
||
284 | * UnMonitor a forum for the given user |
||
285 | * |
||
286 | * @param int $userId |
||
287 | * @return array|null |
||
288 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
289 | * @throws \Freshdesk\Exceptions\ApiException |
||
290 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
291 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
292 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
293 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
294 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
295 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
296 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
297 | * @throws \Freshdesk\Exceptions\ValidationException |
||
298 | */ |
||
299 | View Code Duplication | public function unMonitorForum($id, $userId) |
|
307 | |||
308 | /** |
||
309 | * |
||
310 | * UnMonitor a forum for the given user |
||
311 | * |
||
312 | * @param int $userId |
||
313 | * @return array|null |
||
314 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
315 | * @throws \Freshdesk\Exceptions\ApiException |
||
316 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
317 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
318 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
319 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
320 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
321 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
322 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
323 | * @throws \Freshdesk\Exceptions\ValidationException |
||
324 | */ |
||
325 | View Code Duplication | public function monitorForumStatus($id, $userId) |
|
333 | |||
334 | /** |
||
335 | * |
||
336 | * View all topics for a forum |
||
337 | * |
||
338 | * @param int $id |
||
339 | * @param array|null $query |
||
340 | * @return array|null |
||
341 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
342 | * @throws \Freshdesk\Exceptions\ApiException |
||
343 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
344 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
345 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
346 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
347 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
348 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
349 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
350 | * @throws \Freshdesk\Exceptions\ValidationException |
||
351 | */ |
||
352 | public function viewAllForumTopics($id, array $query = null) |
||
356 | |||
357 | /** |
||
358 | * |
||
359 | * Create a topic for a forum |
||
360 | * |
||
361 | * @param int $id |
||
362 | * @param array $data |
||
363 | * @return array|null |
||
364 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
365 | * @throws \Freshdesk\Exceptions\ApiException |
||
366 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
367 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
368 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
369 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
370 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
371 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
372 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
373 | * @throws \Freshdesk\Exceptions\ValidationException |
||
374 | */ |
||
375 | public function createForumTopic($id, array $data) |
||
379 | |||
380 | /** |
||
381 | * |
||
382 | * View a topic |
||
383 | * |
||
384 | * @param int $id |
||
385 | * @param array $query |
||
386 | * @return array|null |
||
387 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
388 | * @throws \Freshdesk\Exceptions\ApiException |
||
389 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
390 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
391 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
392 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
393 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
394 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
395 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
396 | * @throws \Freshdesk\Exceptions\ValidationException |
||
397 | */ |
||
398 | public function viewTopic($id, array $query = null) |
||
402 | |||
403 | /** |
||
404 | * |
||
405 | * Update a topic |
||
406 | * |
||
407 | * @param int $id |
||
408 | * @param array $data |
||
409 | * @return array|null |
||
410 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
411 | * @throws \Freshdesk\Exceptions\ApiException |
||
412 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
413 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
414 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
415 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
416 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
417 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
418 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
419 | * @throws \Freshdesk\Exceptions\ValidationException |
||
420 | */ |
||
421 | public function updateTopic($id, array $data) |
||
425 | |||
426 | /** |
||
427 | * |
||
428 | * Delete a topic |
||
429 | * |
||
430 | * @param int $id |
||
431 | * @return array|null |
||
432 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
433 | * @throws \Freshdesk\Exceptions\ApiException |
||
434 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
435 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
436 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
437 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
438 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
439 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
440 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
441 | * @throws \Freshdesk\Exceptions\ValidationException |
||
442 | */ |
||
443 | public function deleteTopic($id) |
||
447 | |||
448 | /** |
||
449 | * |
||
450 | * List comments in a topic |
||
451 | * |
||
452 | * @param int $id |
||
453 | * @param array $query |
||
454 | * @return array|null |
||
455 | * @throws \Freshdesk\Exceptions\AccessDeniedException |
||
456 | * @throws \Freshdesk\Exceptions\ApiException |
||
457 | * @throws \Freshdesk\Exceptions\AuthenticationException |
||
458 | * @throws \Freshdesk\Exceptions\ConflictingStateException |
||
459 | * @throws \Freshdesk\Exceptions\NotFoundException |
||
460 | * @throws \Freshdesk\Exceptions\RateLimitExceededException |
||
461 | * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException |
||
462 | * @throws \Freshdesk\Exceptions\MethodNotAllowedException |
||
463 | * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException |
||
464 | * @throws \Freshdesk\Exceptions\ValidationException |
||
465 | */ |
||
466 | public function allTopicComments($id, array $query = null) |
||
470 | |||
471 | |||
472 | } |
||
473 |
This check marks private properties in classes that are never used. Those properties can be removed.