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 |
||
| 20 | class Watching extends AbstractPackage |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * List watchers |
||
| 24 | * |
||
| 25 | * @param string $owner Repository owner. |
||
| 26 | * @param string $repo Repository name. |
||
| 27 | * |
||
| 28 | * @return mixed |
||
| 29 | * |
||
| 30 | * @since 1.0 |
||
| 31 | */ |
||
| 32 | public function getList($owner, $repo) |
||
| 41 | |||
| 42 | /** |
||
| 43 | * List repositories being watched. |
||
| 44 | * |
||
| 45 | * List repositories being watched by a user. |
||
| 46 | * |
||
| 47 | * @param string $user User name. |
||
| 48 | * |
||
| 49 | * @return mixed |
||
| 50 | * |
||
| 51 | * @since 1.0 |
||
| 52 | */ |
||
| 53 | View Code Duplication | public function getRepositories($user = '') |
|
| 64 | |||
| 65 | /** |
||
| 66 | * Get a Repository Subscription. |
||
| 67 | * |
||
| 68 | * @param string $owner Repository owner. |
||
| 69 | * @param string $repo Repository name. |
||
| 70 | * |
||
| 71 | * @return object |
||
| 72 | * |
||
| 73 | * @since 1.0 |
||
| 74 | */ |
||
| 75 | public function getSubscription($owner, $repo) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Set a Repository Subscription. |
||
| 87 | * |
||
| 88 | * @param string $owner Repository owner. |
||
| 89 | * @param string $repo Repository name. |
||
| 90 | * @param boolean $subscribed Determines if notifications should be received from this thread. |
||
| 91 | * @param boolean $ignored Determines if all notifications should be blocked from this thread. |
||
| 92 | * |
||
| 93 | * @return object |
||
| 94 | * |
||
| 95 | * @since 1.0 |
||
| 96 | */ |
||
| 97 | public function setSubscription($owner, $repo, $subscribed, $ignored) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Delete a Repository Subscription. |
||
| 114 | * |
||
| 115 | * @param string $owner Repository owner. |
||
| 116 | * @param string $repo Repository name. |
||
| 117 | * |
||
| 118 | * @return object |
||
| 119 | * |
||
| 120 | * @since 1.0 |
||
| 121 | */ |
||
| 122 | View Code Duplication | public function deleteSubscription($owner, $repo) |
|
| 132 | |||
| 133 | /** |
||
| 134 | * Check if you are watching a repository (LEGACY). |
||
| 135 | * |
||
| 136 | * Requires for the user to be authenticated. |
||
| 137 | * |
||
| 138 | * @param string $owner Repository owner. |
||
| 139 | * @param string $repo Repository name. |
||
| 140 | * |
||
| 141 | * @return boolean |
||
| 142 | * |
||
| 143 | * @since 1.0 |
||
| 144 | * @throws \UnexpectedValueException |
||
| 145 | */ |
||
| 146 | public function check($owner, $repo) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Watch a repository (LEGACY). |
||
| 171 | * |
||
| 172 | * Requires for the user to be authenticated. |
||
| 173 | * |
||
| 174 | * @param string $owner Repository owner. |
||
| 175 | * @param string $repo Repository name. |
||
| 176 | * |
||
| 177 | * @return object |
||
| 178 | * |
||
| 179 | * @since 1.0 |
||
| 180 | */ |
||
| 181 | public function watch($owner, $repo) |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Stop watching a repository (LEGACY). |
||
| 194 | * |
||
| 195 | * Requires for the user to be authenticated. |
||
| 196 | * |
||
| 197 | * @param string $owner Repository owner. |
||
| 198 | * @param string $repo Repository name. |
||
| 199 | * |
||
| 200 | * @return object |
||
| 201 | * |
||
| 202 | * @since 1.0 |
||
| 203 | */ |
||
| 204 | public function unwatch($owner, $repo) |
||
| 214 | } |
||
| 215 |
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.