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 |
||
13 | class BuyableStockManualUpdate extends DataObject |
||
|
|||
14 | { |
||
15 | private static $db = array( |
||
16 | "Quantity" => "Int", |
||
17 | "ExternalUpdate" => "Boolean" |
||
18 | ); |
||
19 | |||
20 | private static $has_one = array( |
||
21 | "Parent" => "BuyableStockCalculatedQuantity", |
||
22 | "Member" => "Member" |
||
23 | ); |
||
24 | |||
25 | //MODEL ADMIN STUFF |
||
26 | |||
27 | private static $searchable_fields = array( |
||
28 | "Quantity", |
||
29 | "MemberID" |
||
30 | ); |
||
31 | |||
32 | private static $field_labels = array( |
||
33 | "Quantity", |
||
34 | "ParentID" => "Buyable", |
||
35 | "MemberID" => "Updated by ..." |
||
36 | ); |
||
37 | |||
38 | private static $summary_fields = array( |
||
39 | "Parent.Name" => "Buyable", |
||
40 | "Member.FirstName" => "Updater", |
||
41 | "Quantity" => "Quantity" |
||
42 | ); |
||
43 | |||
44 | private static $api_access = true; |
||
45 | |||
46 | |||
47 | private static $indexes = [ |
||
48 | 'LastEdited' => true |
||
49 | ]; |
||
50 | |||
51 | private static $default_sort = [ |
||
52 | 'LastEdited' => 'DESC', |
||
53 | 'ParentID' => 'ASC', |
||
54 | 'ID' => 'DESC' |
||
55 | ]; |
||
56 | |||
57 | private static $singular_name = "Stock Manual Update Entry"; |
||
58 | public function i18n_singular_name() |
||
62 | |||
63 | private static $plural_name = "Stock Manual Update Entries"; |
||
64 | public function i18n_plural_name() |
||
68 | |||
69 | public function canView($member = null) |
||
73 | |||
74 | public function canCreate($member = null) |
||
78 | |||
79 | public function canEdit($member = null) |
||
83 | |||
84 | public function canDelete($member = null) |
||
88 | |||
89 | View Code Duplication | protected function canDoAnything($member = null) |
|
97 | } |
||
98 |
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.