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 |
||
| 11 | class PickUpOrDeliveryModifierOptions_WeightBracket extends DataObject |
||
|
|
|||
| 12 | { |
||
| 13 | private static $db = array( |
||
| 14 | "Name" => "Varchar", |
||
| 15 | "MinimumWeight" => "Int", |
||
| 16 | "MaximumWeight" => "Int", |
||
| 17 | "FixedCost" => "Currency" |
||
| 18 | ); |
||
| 19 | |||
| 20 | private static $belongs_many_many = array( |
||
| 21 | "PickUpOrDeliveryModifierOptions" => "PickUpOrDeliveryModifierOptions" |
||
| 22 | ); |
||
| 23 | |||
| 24 | private static $indexes = array( |
||
| 25 | "MinimumWeight" => true, |
||
| 26 | "MaximumWeight" => true |
||
| 27 | ); |
||
| 28 | |||
| 29 | private static $searchable_fields = array( |
||
| 30 | "Name" => "PartialMatchFilter" |
||
| 31 | ); |
||
| 32 | |||
| 33 | private static $field_labels = array( |
||
| 34 | "Name" => "Description (e.g. small parcel)", |
||
| 35 | "MinimumWeight" => "The minimum weight in grams", |
||
| 36 | "MaximumWeight" => "The maximum weight in grams", |
||
| 37 | "FixedCost" => "Total price (fixed cost)" |
||
| 38 | ); |
||
| 39 | |||
| 40 | private static $summary_fields = array( |
||
| 41 | "Name", |
||
| 42 | "MinimumWeight", |
||
| 43 | "MaximumWeight", |
||
| 44 | "FixedCost" |
||
| 45 | ); |
||
| 46 | |||
| 47 | private static $singular_name = "Weight Bracket"; |
||
| 48 | |||
| 49 | public function i18n_singular_name() |
||
| 53 | |||
| 54 | private static $plural_name = "Weight Brackets"; |
||
| 55 | |||
| 56 | public function i18n_plural_name() |
||
| 60 | |||
| 61 | private static $default_sort = "MinimumWeight ASC, MaximumWeight ASC"; |
||
| 62 | |||
| 63 | |||
| 64 | /** |
||
| 65 | * standard SS method |
||
| 66 | * @param Member | NULL |
||
| 67 | * @return Boolean |
||
| 68 | */ |
||
| 69 | View Code Duplication | public function canCreate($member = null) |
|
| 76 | |||
| 77 | /** |
||
| 78 | * standard SS method |
||
| 79 | * @param Member | NULL |
||
| 80 | * @return Boolean |
||
| 81 | */ |
||
| 82 | public function canView($member = null) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * standard SS method |
||
| 89 | * @param Member | NULL |
||
| 90 | * @return Boolean |
||
| 91 | */ |
||
| 92 | View Code Duplication | public function canEdit($member = null) |
|
| 99 | |||
| 100 | /** |
||
| 101 | * standard SS method |
||
| 102 | * @param Member | NULL |
||
| 103 | * @return Boolean |
||
| 104 | */ |
||
| 105 | View Code Duplication | public function canDelete($member = null) |
|
| 112 | } |
||
| 113 |
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.