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 |
||
18 | class Guzzle6ApiClientFactory extends AbstractApiClientFactory |
||
19 | { |
||
20 | /** |
||
21 | * Use the Guzzle6-specific API client class. |
||
22 | * |
||
23 | * @return string |
||
24 | */ |
||
25 | 1 | protected function getApiClientClass() |
|
29 | |||
30 | 1 | protected function getGuzzleBaseUriOptionKey() |
|
34 | |||
35 | /** |
||
36 | * Instantiate a TokenMiddleware instance with a TokenManager. |
||
37 | * |
||
38 | * @param TokenManager $tokenManager |
||
39 | * |
||
40 | * @return TokenMiddleware |
||
41 | */ |
||
42 | 2 | public function createTokenMiddleware(TokenManager $tokenManager) |
|
46 | |||
47 | /** |
||
48 | * Method to instantiate a HTTP client. |
||
49 | * |
||
50 | * @param string $baseUri |
||
51 | * @param array $middlewares |
||
52 | * @param array $options |
||
53 | * |
||
54 | * @return ClientInterface |
||
55 | */ |
||
56 | 1 | public function createHttpClient($baseUri, array $middlewares = [], array $options = []) |
|
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | View Code Duplication | public function createSimple($baseUri, ApiCredentials $credentials) |
|
81 | } |
||
82 |
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.