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 |
||
22 | class Cart extends \eoxia\Singleton_Util { |
||
23 | |||
24 | /** |
||
25 | * Constructeur pour la classe Cart. Charge les options et les actions. |
||
26 | * |
||
27 | * @since 2.0.0 |
||
28 | */ |
||
29 | protected function construct() {} |
||
30 | |||
31 | /** |
||
32 | * Ajout d'un produit dans le panier |
||
33 | * |
||
34 | * @since 2.0.0 |
||
35 | * |
||
36 | * @param Product_Model $product Les données du produit. |
||
37 | */ |
||
38 | public function add_to_cart( $product ) { |
||
67 | |||
68 | /** |
||
69 | * Met à jour le contenu du panier |
||
70 | * |
||
71 | * @since 2.0.0 |
||
72 | * |
||
73 | * @param Product_Model $product Les données du produit. |
||
74 | */ |
||
75 | public function update_cart( $product ) { |
||
90 | |||
91 | /** |
||
92 | * Supprimes un produit du panier. |
||
93 | * |
||
94 | * @since 2.0.0 |
||
95 | * |
||
96 | * @param integer $key La clé du produit dans le tableau. |
||
97 | */ |
||
98 | public function delete_product( $key ) { |
||
106 | } |
||
107 | |||
109 |
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.