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 |
||
14 | class Customers extends Client |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * Retrieve customers |
||
19 | * |
||
20 | * Get a list of customers. |
||
21 | * |
||
22 | * @return $this |
||
23 | */ |
||
24 | View Code Duplication | public function all(): self |
|
33 | |||
34 | /** |
||
35 | * Create a new customer. |
||
36 | * |
||
37 | * Please note there is a limit to the number of customers that can be imported in Bookeo. Bookeo is primarily a booking system, not a CRM. |
||
38 | * |
||
39 | * @param Customer $customer |
||
40 | * @return Customers |
||
41 | */ |
||
42 | View Code Duplication | public function create(Customer $customer): self |
|
52 | } |
||
53 |
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.