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 |
||
14 | class Guzzle6ApiClient extends AbstractApiClient implements ApiClientInterface |
||
15 | { |
||
16 | /** |
||
17 | * Guzzle6 Client implementation for making HTTP requests with |
||
18 | * the appropriate options. |
||
19 | * |
||
20 | * @param string $method |
||
21 | * @param string $uri |
||
22 | * @param array $options |
||
23 | * |
||
24 | * @return mixed |
||
25 | */ |
||
26 | protected function _doRequest($method, $uri, $options) |
||
30 | |||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | * |
||
34 | * @param ResponseInterface $response |
||
35 | * |
||
36 | * @return string |
||
37 | */ |
||
38 | View Code Duplication | protected function serializeResponse($response) |
|
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | * |
||
56 | * @param string $serialized |
||
57 | * |
||
58 | * @return ResponseInterface |
||
59 | * |
||
60 | * @throws Exception |
||
61 | */ |
||
62 | protected function unserializeResponse($serialized) |
||
71 | } |
||
72 |
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.