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 |
||
5 | class EcommerceAlsoRecommendedDOD extends DataExtension |
||
|
|||
6 | { |
||
7 | private static $many_many = array( |
||
8 | 'EcommerceRecommendedProducts' => 'Product' |
||
9 | ); |
||
10 | |||
11 | private static $belongs_many_many = array( |
||
12 | 'RecommendedFor' => 'Product' |
||
13 | ); |
||
14 | |||
15 | public function updateCMSFields(FieldList $fields) |
||
43 | |||
44 | /** |
||
45 | * |
||
46 | * small cleanup |
||
47 | */ |
||
48 | public function onAfterWrite() |
||
71 | |||
72 | /** |
||
73 | * only returns the products that are for sale |
||
74 | * if only those need to be showing. |
||
75 | * @return DataList |
||
76 | */ |
||
77 | View Code Duplication | public function EcommerceRecommendedProductsForSale() |
|
85 | |||
86 | /** |
||
87 | * only returns the products that are for sale |
||
88 | * if only those need to be showing. |
||
89 | * @return DataList |
||
90 | */ |
||
91 | View Code Duplication | public function RecommendedForForSale() |
|
99 | } |
||
100 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.