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 Keys extends AbstractPackage |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * List public keys for a user. |
||
| 24 | * |
||
| 25 | * Lists the verified public keys for a user. This is accessible by anyone. |
||
| 26 | * |
||
| 27 | * @param string $user The name of the user. |
||
| 28 | * |
||
| 29 | * @return object |
||
| 30 | * |
||
| 31 | * @since 1.0 |
||
| 32 | */ |
||
| 33 | View Code Duplication | public function getListUser($user) |
|
| 42 | |||
| 43 | /** |
||
| 44 | * List your public keys. |
||
| 45 | * |
||
| 46 | * Lists the current user’s keys. |
||
| 47 | * Management of public keys via the API requires that you are authenticated |
||
| 48 | * through basic auth, or OAuth with the ‘user’ scope. |
||
| 49 | * |
||
| 50 | * @return object |
||
| 51 | * |
||
| 52 | * @since 1.0 |
||
| 53 | */ |
||
| 54 | public function getList() |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Get a single public key. |
||
| 66 | * |
||
| 67 | * @param integer $id The id of the key. |
||
| 68 | * |
||
| 69 | * @return object |
||
| 70 | * |
||
| 71 | * @since 1.0 |
||
| 72 | */ |
||
| 73 | public function get($id) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Create a public key |
||
| 85 | * |
||
| 86 | * @param string $title The title of the key. |
||
| 87 | * @param string $key The key. |
||
| 88 | * |
||
| 89 | * @return object |
||
| 90 | * |
||
| 91 | * @since 1.0 |
||
| 92 | */ |
||
| 93 | View Code Duplication | public function create($title, $key) |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Update a public key. |
||
| 111 | * |
||
| 112 | * @param integer $id The id of the key. |
||
| 113 | * @param string $title The title of the key. |
||
| 114 | * @param string $key The key. |
||
| 115 | * |
||
| 116 | * @return object |
||
| 117 | * |
||
| 118 | * @since 1.0 |
||
| 119 | */ |
||
| 120 | View Code Duplication | public function edit($id, $title, $key) |
|
| 134 | |||
| 135 | /** |
||
| 136 | * Delete a public key. |
||
| 137 | * |
||
| 138 | * @param integer $id The id of the key. |
||
| 139 | * |
||
| 140 | * @return object |
||
| 141 | * |
||
| 142 | * @since 1.0 |
||
| 143 | */ |
||
| 144 | View Code Duplication | public function delete($id) |
|
| 154 | } |
||
| 155 |
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.