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 |
||
19 | abstract class AbstractTransport implements TransportInterface |
||
20 | { |
||
21 | /** |
||
22 | * List of cURL options. |
||
23 | * |
||
24 | * @var \Jgut\Spiral\Option[] |
||
25 | */ |
||
26 | protected $options = []; |
||
27 | |||
28 | /** |
||
29 | * Retrieve added cURL options. |
||
30 | * |
||
31 | * @return \Jgut\Spiral\Option[] |
||
32 | */ |
||
33 | public function getOptions() |
||
37 | |||
38 | /** |
||
39 | * Set cURL options. |
||
40 | * |
||
41 | * @param array $options |
||
42 | */ |
||
43 | public function setOptions(array $options) |
||
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | public function setOption($option, $value = '', $quiet = false) |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public function hasOption($option, $value = null) |
||
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | public function removeOption($option) |
||
116 | |||
117 | /** |
||
118 | * Shorthand for OPTIONS cURL request. |
||
119 | * |
||
120 | * @param string $uri |
||
121 | * @param array $headers |
||
122 | * @param array $vars |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | public function options($uri, array $headers = [], array $vars = []) |
||
130 | |||
131 | /** |
||
132 | * Shorthand for HEAD cURL request. |
||
133 | * |
||
134 | * @param string $uri |
||
135 | * @param array $headers |
||
136 | * @param array $vars |
||
137 | * |
||
138 | * @return string |
||
139 | */ |
||
140 | public function head($uri, array $headers = [], array $vars = []) |
||
144 | |||
145 | /** |
||
146 | * Shorthand for GET cURL request. |
||
147 | * |
||
148 | * @param string $uri |
||
149 | * @param array $headers |
||
150 | * @param array $vars |
||
151 | * |
||
152 | * @return string |
||
153 | */ |
||
154 | public function get($uri, array $headers = [], array $vars = []) |
||
158 | |||
159 | /** |
||
160 | * Shorthand for POST cURL request. |
||
161 | * |
||
162 | * @param string $uri |
||
163 | * @param array $headers |
||
164 | * @param array $vars |
||
165 | * @param array $flags |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | public function post($uri, array $headers = [], array $vars = [], array $flags = []) |
||
173 | |||
174 | /** |
||
175 | * Shorthand for PUT cURL request. |
||
176 | * |
||
177 | * @param string $uri |
||
178 | * @param array $headers |
||
179 | * @param array $vars |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | public function put($uri, array $headers = [], array $vars = []) |
||
187 | |||
188 | /** |
||
189 | * Shorthand for DELETE cURL request. |
||
190 | * |
||
191 | * @param string $uri |
||
192 | * @param array $headers |
||
193 | * @param array $vars |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | public function delete($uri, array $headers = [], array $vars = []) |
||
201 | |||
202 | /** |
||
203 | * Shorthand for PATCH cURL request. |
||
204 | * |
||
205 | * @param string $uri |
||
206 | * @param array $headers |
||
207 | * @param array $vars |
||
208 | * |
||
209 | * @return string |
||
210 | */ |
||
211 | public function patch($uri, array $headers = [], array $vars = []) |
||
215 | } |
||
216 |
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.