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 |
||
9 | class Contract extends Api |
||
10 | { |
||
11 | /** |
||
12 | * @param string $id |
||
13 | * @param string $contractAddress |
||
14 | * @return array |
||
15 | * @throws Exception |
||
16 | */ |
||
17 | 1 | public function getContract(string $id, string $contractAddress): array |
|
21 | |||
22 | /** |
||
23 | * @param string $id |
||
24 | * @param string $contractAddress |
||
25 | * @param string $vsCurrency |
||
26 | * @param string $days |
||
27 | * @return array |
||
28 | * @throws Exception |
||
29 | */ |
||
30 | 1 | public function getMarketChart(string $id, string $contractAddress, string $vsCurrency, string $days): array |
|
36 | |||
37 | /** |
||
38 | * @param string $id |
||
39 | * @param string $contractAddress |
||
40 | * @param string $vsCurrency |
||
41 | * @param string $from |
||
42 | * @param string $to |
||
43 | * @return array |
||
44 | * @throws Exception |
||
45 | */ |
||
46 | 1 | View Code Duplication | public function getMarketChartRange( |
58 | } |
||
59 |
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.