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 |
||
21 | View Code Duplication | class GuzzleHttpConnector implements ConnectorInterface |
|
|
|||
22 | { |
||
23 | |||
24 | /** |
||
25 | * Establish an adapter connection. |
||
26 | * |
||
27 | * @param string[] $config |
||
28 | * |
||
29 | * @return \IlGala\SMSFactor\Adapters\GuzzleHttpAdapter |
||
30 | */ |
||
31 | public function connect(array $config) |
||
36 | |||
37 | /** |
||
38 | * Get the configuration. |
||
39 | * |
||
40 | * @param string[] $config |
||
41 | * |
||
42 | * @throws \InvalidArgumentException |
||
43 | * |
||
44 | * @return string[] |
||
45 | */ |
||
46 | protected function getConfig(array $config) |
||
53 | |||
54 | /** |
||
55 | * Get the guzzlehttp adapter. |
||
56 | * |
||
57 | * @param string[] $config |
||
58 | * |
||
59 | * @return \IlGala\SMSFactor\Adapters\GuzzleHttpAdapter |
||
60 | */ |
||
61 | protected function getAdapter(array $config) |
||
65 | |||
66 | } |
||
67 |
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.