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 |
||
24 | View Code Duplication | final class Stats implements Api |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * Show some diagnostic information on the bitswap agent. |
||
28 | * |
||
29 | * @Endpoint(name="stats:bitswap") |
||
30 | * |
||
31 | * @return Command |
||
32 | */ |
||
33 | public function bitswap(): Command |
||
37 | |||
38 | /** |
||
39 | * Print ipfs bandwidth information. |
||
40 | * |
||
41 | * @Endpoint(name="stats:bw") |
||
42 | * |
||
43 | * @param string $peer specify a peer to print bandwidth for |
||
44 | * @param string $proto specify a protocol to print bandwidth for |
||
45 | * @param bool $poll print bandwidth at an interval |
||
46 | * @param string $interval time interval to wait between updating output, if ‘poll’ is true |
||
47 | * |
||
48 | * @return Command |
||
49 | */ |
||
50 | public function bw(string $peer = null, string $proto = null, bool $poll = false, string $interval = null): Command |
||
54 | |||
55 | /** |
||
56 | * Get stats for the currently used repo. |
||
57 | * |
||
58 | * @Endpoint(name="stats:repo") |
||
59 | * |
||
60 | * @param bool $human output RepoSize in MiB |
||
61 | * |
||
62 | * @return Command |
||
63 | */ |
||
64 | public function repo(bool $human = false): Command |
||
68 | } |
||
69 |
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.