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 |
||
21 | class Notifications extends AbstractPackage |
||
22 | { |
||
23 | /** |
||
24 | * List your notifications. |
||
25 | * |
||
26 | * List all notifications for the current user, grouped by repository. |
||
27 | * |
||
28 | * @param boolean $all True to show notifications marked as read. |
||
29 | * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. |
||
30 | * @param \DateTime $since Only show notifications updated after the given time. |
||
31 | * @param \DateTime $before Only show notifications updated before the given time. |
||
32 | * |
||
33 | * @return object |
||
34 | * |
||
35 | * @since 1.0 |
||
36 | */ |
||
37 | public function getList($all = true, $participating = true, \DateTime $since = null, \DateTime $before = null) |
||
68 | |||
69 | /** |
||
70 | * List your notifications in a repository. |
||
71 | * |
||
72 | * List all notifications for the current user. |
||
73 | * |
||
74 | * @param string $owner Repository owner. |
||
75 | * @param string $repo Repository name. |
||
76 | * @param boolean $all True to show notifications marked as read. |
||
77 | * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. |
||
78 | * @param \DateTime $since Only show notifications updated after the given time. |
||
79 | * @param \DateTime $before Only show notifications updated before the given time. |
||
80 | * |
||
81 | * @return object |
||
82 | * |
||
83 | * @since 1.0 |
||
84 | */ |
||
85 | public function getListRepository($owner, $repo, $all = true, $participating = true, \DateTime $since = null, \DateTime $before = null) |
||
116 | |||
117 | /** |
||
118 | * Mark as read. |
||
119 | * |
||
120 | * Marking a notification as “read” removes it from the default view on GitHub.com. |
||
121 | * |
||
122 | * @param boolean $unread Changes the unread status of the threads. |
||
123 | * @param boolean $read Inverse of “unread”. |
||
124 | * @param \DateTime $lastReadAt Describes the last point that notifications were checked. |
||
125 | * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. |
||
126 | * |
||
127 | * @return object |
||
128 | * |
||
129 | * @since 1.0 |
||
130 | */ |
||
131 | public function markRead($unread = true, $read = true, \DateTime $lastReadAt = null) |
||
151 | |||
152 | /** |
||
153 | * Mark notifications as read in a repository. |
||
154 | * |
||
155 | * Marking all notifications in a repository as “read” removes them from the default view on GitHub.com. |
||
156 | * |
||
157 | * @param string $owner Repository owner. |
||
158 | * @param string $repo Repository name. |
||
159 | * @param boolean $unread Changes the unread status of the threads. |
||
160 | * @param boolean $read Inverse of “unread”. |
||
161 | * @param \DateTime $lastReadAt Describes the last point that notifications were checked. |
||
162 | * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. |
||
163 | * |
||
164 | * @return object |
||
165 | * |
||
166 | * @since 1.0 |
||
167 | */ |
||
168 | public function markReadRepository($owner, $repo, $unread, $read, \DateTime $lastReadAt = null) |
||
188 | |||
189 | /** |
||
190 | * View a single thread. |
||
191 | * |
||
192 | * @param integer $id The thread id. |
||
193 | * |
||
194 | * @return object |
||
195 | * |
||
196 | * @since 1.0 |
||
197 | */ |
||
198 | public function viewThread($id) |
||
207 | |||
208 | /** |
||
209 | * Mark a thread as read. |
||
210 | * |
||
211 | * @param integer $id The thread id. |
||
212 | * @param boolean $unread Changes the unread status of the threads. |
||
213 | * @param boolean $read Inverse of “unread”. |
||
214 | * |
||
215 | * @return object |
||
216 | * |
||
217 | * @since 1.0 |
||
218 | */ |
||
219 | View Code Duplication | public function markReadThread($id, $unread = true, $read = true) |
|
234 | |||
235 | /** |
||
236 | * Get a Thread Subscription. |
||
237 | * |
||
238 | * This checks to see if the current user is subscribed to a thread. |
||
239 | * You can also get a Repository subscription. |
||
240 | * |
||
241 | * @param integer $id The thread id. |
||
242 | * |
||
243 | * @return object |
||
244 | * |
||
245 | * @since 1.0 |
||
246 | */ |
||
247 | View Code Duplication | public function getThreadSubscription($id) |
|
256 | |||
257 | /** |
||
258 | * Set a Thread Subscription. |
||
259 | * |
||
260 | * This lets you subscribe to a thread, or ignore it. Subscribing to a thread is unnecessary |
||
261 | * if the user is already subscribed to the repository. Ignoring a thread will mute all |
||
262 | * future notifications (until you comment or get @mentioned). |
||
263 | * |
||
264 | * @param integer $id The thread id. |
||
265 | * @param boolean $subscribed Determines if notifications should be received from this thread. |
||
266 | * @param boolean $ignored Determines if all notifications should be blocked from this thread. |
||
267 | * |
||
268 | * @return object |
||
269 | * |
||
270 | * @since 1.0 |
||
271 | */ |
||
272 | View Code Duplication | public function setThreadSubscription($id, $subscribed, $ignored) |
|
286 | |||
287 | /** |
||
288 | * Delete a Thread Subscription. |
||
289 | * |
||
290 | * @param integer $id The thread id. |
||
291 | * |
||
292 | * @return object |
||
293 | * |
||
294 | * @since 1.0 |
||
295 | */ |
||
296 | View Code Duplication | public function deleteThreadSubscription($id) |
|
306 | } |
||
307 |
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.