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 |
||
18 | View Code Duplication | class Maps extends Api |
|
|
|||
19 | { |
||
20 | /** |
||
21 | * List maps |
||
22 | * List configured maps |
||
23 | */ |
||
24 | public function maps() |
||
28 | |||
29 | /** |
||
30 | * Create a map |
||
31 | * Create a new map |
||
32 | * |
||
33 | * @param array $global_pools Sorted list of pool IDs that will be utilized |
||
34 | * if a CF PoP cannot be assigned to a configured region. |
||
35 | * @param string|null $description Object description. |
||
36 | */ |
||
37 | public function create($global_pools, $description = null) |
||
46 | |||
47 | /** |
||
48 | * Map details |
||
49 | * Fetch a single configured map |
||
50 | * |
||
51 | * @param string $identifier |
||
52 | */ |
||
53 | public function details($identifier) |
||
57 | |||
58 | /** |
||
59 | * Modify a map |
||
60 | * Modify a configured map |
||
61 | * |
||
62 | * @param string $identifier |
||
63 | * @param array $global_pools Sorted list of pool IDs that will be utilized |
||
64 | * if a CF PoP cannot be assigned to a configured region. |
||
65 | * @param string|null $description Object description. |
||
66 | */ |
||
67 | public function update($identifier, $global_pools = null, $description = null) |
||
76 | |||
77 | /** |
||
78 | * Delete a map |
||
79 | * Delete a configured map |
||
80 | * |
||
81 | * @param string $identifier |
||
82 | */ |
||
83 | public function delete_map($identifier) |
||
87 | } |
||
88 |
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.