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 GSTTaxDecorator extends DataExtension |
||
|
|||
15 | { |
||
16 | |||
17 | /** |
||
18 | * standard SS method |
||
19 | * @return Array |
||
20 | */ |
||
21 | private static $many_many = array( |
||
22 | "ExcludedFrom" => "GSTTaxModifierOptions", |
||
23 | "AdditionalTax" => "GSTTaxModifierOptions" |
||
24 | ); |
||
25 | |||
26 | /** |
||
27 | * for variations, use product for data |
||
28 | * @return DataList |
||
29 | */ |
||
30 | View Code Duplication | public function BuyableCalculatedExcludedFrom() |
|
39 | |||
40 | /** |
||
41 | * for variations, use product for data |
||
42 | * @return DataList |
||
43 | */ |
||
44 | View Code Duplication | public function BuyableCalculatedAdditionalTax() |
|
53 | |||
54 | |||
55 | /** |
||
56 | * standard SS method |
||
57 | * @param Object - $fields (FieldList) |
||
58 | * @return Object - FieldList |
||
59 | */ |
||
60 | public function updateCMSFields(FieldList $fields) |
||
124 | |||
125 | /** |
||
126 | * returns the calculated price for the buyable including tax |
||
127 | * @return float |
||
128 | * |
||
129 | */ |
||
130 | public function TaxInclusivePrice() |
||
134 | |||
135 | /** |
||
136 | * returns the calculated price for the buyable excluding tax |
||
137 | * @return float |
||
138 | * |
||
139 | */ |
||
140 | public function TaxExclusivePrice() |
||
144 | } |
||
145 |
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.