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 |
||
23 | class Hooks extends AbstractPackage |
||
24 | { |
||
25 | /** |
||
26 | * List hooks. |
||
27 | * |
||
28 | * @param string $org The name of the organization. |
||
29 | * |
||
30 | * @return object |
||
31 | * |
||
32 | * @since 1.4.0 |
||
33 | */ |
||
34 | public function getList($org) |
||
43 | |||
44 | /** |
||
45 | * Get single hook. |
||
46 | * |
||
47 | * @param string $org The name of the organization. |
||
48 | * @param integer $id The hook id. |
||
49 | * |
||
50 | * @return object |
||
51 | * |
||
52 | * @since 1.4.0 |
||
53 | */ |
||
54 | View Code Duplication | public function get($org, $id) |
|
63 | |||
64 | /** |
||
65 | * Create a hook. |
||
66 | * |
||
67 | * @param string $org The name of the organization. |
||
68 | * @param string $url The URL to which the payloads will be delivered. |
||
69 | * @param string $contentType The media type used to serialize the payloads. Supported values include "json" and "form". |
||
70 | * @param string $secret If provided, payloads will be delivered with an X-Hub-Signature header. |
||
71 | * The value of this header is computed as the |
||
72 | * [HMAC hex digest of the body, using the secret as the key][hub-signature]. |
||
73 | * @param boolean $insecureSsl Determines whether the SSL certificate of the host for url will be verified when delivering payloads. |
||
74 | * If false, verification is performed. If true, verification is not performed. |
||
75 | * @param array $events Determines what events the hook is triggered for. |
||
76 | * @param boolean $active Determines whether the hook is actually triggered on pushes. |
||
77 | * |
||
78 | * @return object |
||
79 | * |
||
80 | * @since 1.4.0 |
||
81 | * @throws \UnexpectedValueException |
||
82 | */ |
||
83 | public function create($org, $url, $contentType = 'form', $secret = null, $insecureSsl = false, array $events = array('push'), $active = true) |
||
129 | |||
130 | /** |
||
131 | * Edit a hook. |
||
132 | * |
||
133 | * @param string $org The name of the organization. |
||
134 | * @param string $url The URL to which the payloads will be delivered. |
||
135 | * @param string $contentType The media type used to serialize the payloads. Supported values include "json" and "form". |
||
136 | * @param string $secret If provided, payloads will be delivered with an X-Hub-Signature header. |
||
137 | * The value of this header is computed as the |
||
138 | * [HMAC hex digest of the body, using the secret as the key][hub-signature]. |
||
139 | * @param boolean $insecureSsl Determines whether the SSL certificate of the host for url will be verified when delivering payloads. |
||
140 | * If false, verification is performed. If true, verification is not performed. |
||
141 | * @param array $events Determines what events the hook is triggered for. |
||
142 | * @param boolean $active Determines whether the hook is actually triggered on pushes. |
||
143 | * |
||
144 | * @return object |
||
145 | * |
||
146 | * @since 1.4.0 |
||
147 | * @throws \UnexpectedValueException |
||
148 | */ |
||
149 | public function edit($org, $url, $contentType = null, $secret = null, $insecureSsl = null, array $events = array(), $active = null) |
||
206 | |||
207 | /** |
||
208 | * Ping a hook. |
||
209 | * |
||
210 | * @param string $org The name of the organization |
||
211 | * @param integer $id ID of the hook to ping |
||
212 | * |
||
213 | * @return object |
||
214 | * |
||
215 | * @since 1.4.0 |
||
216 | * @throws \DomainException |
||
217 | */ |
||
218 | View Code Duplication | public function ping($org, $id) |
|
228 | |||
229 | /** |
||
230 | * Delete a hook. |
||
231 | * |
||
232 | * @param string $org The name of the organization |
||
233 | * @param integer $id ID of the hook to delete |
||
234 | * |
||
235 | * @return object |
||
236 | * |
||
237 | * @since 1.4.0 |
||
238 | */ |
||
239 | public function delete($org, $id) |
||
249 | } |
||
250 |
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.