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 |
||
15 | class SupportSugarcrm implements DocProviderInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var Client |
||
19 | */ |
||
20 | private $httpClient; |
||
21 | |||
22 | /** |
||
23 | * @var Cache |
||
24 | */ |
||
25 | private $cache; |
||
26 | |||
27 | /** |
||
28 | * @var HtmlConverter |
||
29 | */ |
||
30 | private $htmlConverter; |
||
31 | |||
32 | /** |
||
33 | * SupportSugarcrm constructor. |
||
34 | * |
||
35 | * @param Cache $cache |
||
36 | * @param HtmlConverter $htmlConverter |
||
37 | */ |
||
38 | public function __construct(Cache $cache, HtmlConverter $htmlConverter) |
||
44 | |||
45 | /** |
||
46 | * Get all available SugarCRM versions (sorted ASC). |
||
47 | * |
||
48 | * @param string $flav |
||
49 | * |
||
50 | * @return OrderedList |
||
51 | */ |
||
52 | public function getVersions($flav) |
||
82 | |||
83 | /** |
||
84 | * @param string $flav |
||
85 | * @param OrderedList $versions |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | public function getReleaseNotes($flav, OrderedList $versions) |
||
157 | |||
158 | /** |
||
159 | * Gets all required information to perform health check. |
||
160 | * |
||
161 | * @param Version $version |
||
162 | * |
||
163 | * @return mixed |
||
164 | */ |
||
165 | public function getHealthCheckInfo(Version $version) |
||
184 | |||
185 | /** |
||
186 | * Gets all required information to perform upgrade. |
||
187 | * |
||
188 | * @param Version $version |
||
189 | * |
||
190 | * @return mixed |
||
191 | */ |
||
192 | public function getUpgraderInfo(Version $version) |
||
220 | |||
221 | /** |
||
222 | * Returns the result (response body) of GET request. |
||
223 | * |
||
224 | * @param string $url |
||
225 | * |
||
226 | * @return string |
||
227 | */ |
||
228 | private function getContent($url) |
||
234 | |||
235 | /** |
||
236 | * @param Version $version |
||
237 | * |
||
238 | * @return string |
||
239 | */ |
||
240 | private function getHealthCheckInfoUri(Version $version) |
||
244 | |||
245 | /** |
||
246 | * @param Version $version |
||
247 | * |
||
248 | * @return string |
||
249 | */ |
||
250 | private function getUpgraderInfoUri(Version $version) |
||
254 | |||
255 | /** |
||
256 | * @param Version $version |
||
257 | * |
||
258 | * @return string |
||
259 | */ |
||
260 | private function getUpgradeGuideUri(Version $version) |
||
267 | |||
268 | /** |
||
269 | * @param string $flav |
||
270 | * @param Version $version |
||
271 | * |
||
272 | * @return string |
||
273 | */ |
||
274 | private function getVersionUri($flav, Version $version) |
||
280 | |||
281 | /** |
||
282 | * Returns version specific release note uri. |
||
283 | * |
||
284 | * @param string $flav |
||
285 | * @param Version $version |
||
286 | * |
||
287 | * @return string |
||
288 | */ |
||
289 | private function getReleaseNotesUri($flav, Version $version) |
||
298 | |||
299 | /** |
||
300 | * Returns cache key. |
||
301 | * |
||
302 | * @param $keyParts |
||
303 | * |
||
304 | * @return string |
||
305 | */ |
||
306 | private function getCacheKey(array $keyParts) |
||
314 | |||
315 | /** |
||
316 | * Lightweight HTML purifier. |
||
317 | * |
||
318 | * @param $html |
||
319 | * @param string $url |
||
320 | * @param array $options |
||
321 | * |
||
322 | * @return string |
||
323 | */ |
||
324 | private function purifyHtml($html, $url = '', $options = []) |
||
339 | |||
340 | /** |
||
341 | * Processes request pool. |
||
342 | * |
||
343 | * @param callable $requests |
||
344 | * @param array $config |
||
345 | * |
||
346 | * @return mixed |
||
347 | */ |
||
348 | private function processRequestPool(callable $requests, $config = []) |
||
357 | } |
||
358 |
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.