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 |
||
12 | class Settings extends Client |
||
13 | { |
||
14 | /** |
||
15 | * Get information about your own API Key |
||
16 | * |
||
17 | * @return $this |
||
18 | */ |
||
19 | View Code Duplication | public function apikeyinfo(): self |
|
27 | |||
28 | /** |
||
29 | * Get information, location and contact details about the business |
||
30 | * |
||
31 | * @return $this |
||
32 | */ |
||
33 | View Code Duplication | public function business(): self |
|
41 | |||
42 | /** |
||
43 | * Retrieve custom fields about customers and participants |
||
44 | * |
||
45 | * @return $this |
||
46 | */ |
||
47 | View Code Duplication | public function customercustomfields(): self |
|
55 | |||
56 | /** |
||
57 | * Retrieve all supported languages |
||
58 | * |
||
59 | * @return $this |
||
60 | */ |
||
61 | View Code Duplication | public function languages(): self |
|
69 | |||
70 | /** |
||
71 | * Retrieve all supported people categories |
||
72 | * |
||
73 | * Retrieve the people categories supported by this account. |
||
74 | * This can include the default ones ("Adults","Children","Infants") and also custom ones defined by the account ("Students", ...) |
||
75 | * |
||
76 | * @return $this |
||
77 | */ |
||
78 | View Code Duplication | public function peoplecategories(): self |
|
86 | |||
87 | /** |
||
88 | * Get information about all the products (things that can be booked) offered. |
||
89 | * 3 types of product are available: |
||
90 | * - fixed are products with a fixed schedule and a given number of seats. Ex a group tour, a class, a workshop |
||
91 | * - fixedCourse are fixed products that are defined as a course, i.e. comprise of a series of dates |
||
92 | * - flexibleTime are products that describe private appointments, i.e. when one booking uses one resource (teacher, consultant, etc) |
||
93 | * |
||
94 | * Although Bookeo applies a minimum amount of caching, it is recommended to cache these results for 10-15 minutes to improve the performance of your application, as product settings change rarely. |
||
95 | * |
||
96 | * @return $this |
||
97 | */ |
||
98 | View Code Duplication | public function products(): self |
|
106 | |||
107 | /** |
||
108 | * Retrieve all available resources |
||
109 | * |
||
110 | * @return $this |
||
111 | */ |
||
112 | View Code Duplication | public function resources(): self |
|
120 | |||
121 | /** |
||
122 | * Retrieve all taxes used by this business |
||
123 | * |
||
124 | * @return $this |
||
125 | */ |
||
126 | View Code Duplication | public function taxes(): self |
|
134 | |||
135 | } |
||
136 |
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.