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 Bitswap implements Api |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * Show the current ledger for a peer. |
||
28 | * |
||
29 | * @Endpoint(name="bitswap:ledger") |
||
30 | * |
||
31 | * @param string $arg the PeerID (B58) of the ledger to inspect |
||
32 | * |
||
33 | * @return Command |
||
34 | */ |
||
35 | public function ledger(string $arg): Command |
||
39 | |||
40 | /** |
||
41 | * Show some diagnostic information on the bitswap agent. |
||
42 | * |
||
43 | * @Endpoint(name="bitswap:stat") |
||
44 | * |
||
45 | * @return Command |
||
46 | */ |
||
47 | public function stat(): Command |
||
51 | |||
52 | /** |
||
53 | * Remove a given block from your wantlist. |
||
54 | * |
||
55 | * @Endpoint(name="bitswap:unwant") |
||
56 | * |
||
57 | * @param string $arg key(s) to remove from your wantlist |
||
58 | * |
||
59 | * @return Command |
||
60 | */ |
||
61 | public function unwant(string $arg): Command |
||
65 | |||
66 | /** |
||
67 | * Show blocks currently on the wantlist. |
||
68 | * |
||
69 | * @Endpoint(name="bitswap:wantlist") |
||
70 | * |
||
71 | * @param string $peer specify which peer to show wantlist for |
||
72 | * |
||
73 | * @return Command |
||
74 | */ |
||
75 | public function wantlist(string $peer = null): Command |
||
79 | } |
||
80 |
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.