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 Filestore implements Api |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * List blocks that are both in the filestore and standard block storage. |
||
28 | * |
||
29 | * @Endpoint(name="filestore:dups") |
||
30 | * |
||
31 | * @return Command |
||
32 | */ |
||
33 | public function dups(): Command |
||
37 | |||
38 | /** |
||
39 | * List objects in filestore. |
||
40 | * |
||
41 | * @Endpoint(name="filestore:ls") |
||
42 | * |
||
43 | * @param string $arg cid of objects to list |
||
44 | * |
||
45 | * @return Command |
||
46 | */ |
||
47 | public function ls(string $arg = null): Command |
||
51 | |||
52 | /** |
||
53 | * Verify objects in filestore. |
||
54 | * |
||
55 | * @Endpoint(name="filestore:verify") |
||
56 | * |
||
57 | * @param string $arg cid of objects to verify |
||
58 | * |
||
59 | * @return Command |
||
60 | */ |
||
61 | public function verify(string $arg = null): Command |
||
65 | } |
||
66 |
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.