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 |
||
10 | class BuyableStockOrderEntry extends DataObject |
||
|
|||
11 | { |
||
12 | private static $db = array( |
||
13 | "Quantity" => "Int", |
||
14 | "IncludeInCurrentCalculation" => "Boolean" |
||
15 | ); |
||
16 | |||
17 | private static $has_one = array( |
||
18 | "Parent" => "BuyableStockCalculatedQuantity", |
||
19 | "Order" => "Order", |
||
20 | ); |
||
21 | |||
22 | private static $defaults = array( |
||
23 | "IncludeInCurrentCalculation" => 1 |
||
24 | ); |
||
25 | |||
26 | |||
27 | //MODEL ADMIN STUFF |
||
28 | private static $searchable_fields = array( |
||
29 | "Quantity", |
||
30 | "IncludeInCurrentCalculation", |
||
31 | "ParentID", |
||
32 | "OrderID", |
||
33 | ); |
||
34 | |||
35 | private static $field_labels = array( |
||
36 | "Quantity" => "Calculated Quantity On Hand", |
||
37 | "IncludeInCurrentCalculation" => "Include in Calculation", |
||
38 | "ParentID" => "Buyable Calculation", |
||
39 | "OrderID" => "Order" |
||
40 | ); |
||
41 | |||
42 | private static $summary_fields = array( |
||
43 | "OrderID", |
||
44 | "ParentID", |
||
45 | "Quantity" |
||
46 | ); |
||
47 | |||
48 | private static $default_sort = "\"LastEdited\" DESC, \"ParentID\" ASC"; |
||
49 | |||
50 | private static $singular_name = "Stock Sale Entry"; |
||
51 | public function i18n_singular_name() |
||
55 | |||
56 | private static $plural_name = "Stock Sale Entries"; |
||
57 | public function i18n_plural_name() |
||
61 | |||
62 | public function canCreate($member = null) |
||
66 | |||
67 | public function canEdit($member = null) |
||
71 | |||
72 | public function canDelete($member = null) |
||
76 | |||
77 | public function canView($member = null) |
||
81 | |||
82 | View Code Duplication | protected function canDoAnything() |
|
90 | |||
91 | public function onAfterWrite() |
||
116 | } |
||
117 |
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.