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 Bootstrap implements Api |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * Add default peers to the bootstrap list. |
||
28 | * |
||
29 | * @Endpoint(name="bootstrap:add:default") |
||
30 | * |
||
31 | * @return Command |
||
32 | */ |
||
33 | public function addDefault(): Command |
||
37 | |||
38 | /** |
||
39 | * Show peers in the bootstrap list. |
||
40 | * |
||
41 | * @Endpoint(name="bootstrap:list") |
||
42 | * |
||
43 | * @return Command |
||
44 | */ |
||
45 | public function list(): Command |
||
49 | |||
50 | /** |
||
51 | * Remove all peers from the bootstrap list. |
||
52 | * |
||
53 | * @Endpoint(name="bootstrap:rm:all") |
||
54 | * |
||
55 | * @return Command |
||
56 | */ |
||
57 | public function rmAll(): Command |
||
61 | } |
||
62 |
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.