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 |
||
8 | class WebPortfolioWhatWeDidDescriptor extends DataObject |
||
|
|||
9 | { |
||
10 | private static $db = array( |
||
11 | "Name" => "Varchar(255)", |
||
12 | "Code" => "Varchar(255)", |
||
13 | "Description" => "Text" |
||
14 | ); |
||
15 | |||
16 | private static $belongs_many_many = array( |
||
17 | "WebPortfolioItem" => "WebPortfolioItem" |
||
18 | ); |
||
19 | |||
20 | private static $default_sort = "Name"; |
||
21 | |||
22 | private static $searchable_fields = array( |
||
23 | "Name" => "PartialMatchFilter", |
||
24 | "Description" => "PartialMatchFilter" |
||
25 | ); |
||
26 | |||
27 | private static $summary_fields = array( |
||
28 | "Name", |
||
29 | "Description" |
||
30 | ); |
||
31 | |||
32 | private static $indexes = array( |
||
33 | "Code" => true |
||
34 | ); |
||
35 | |||
36 | private static $singular_name = "What We Did Descriptor"; |
||
37 | |||
38 | private static $plural_name = "What We Did Descriptors"; |
||
39 | |||
40 | public function Link() |
||
52 | |||
53 | public function getCMSFields() |
||
88 | |||
89 | |||
90 | protected $mergeInto = null; |
||
91 | |||
92 | public function onAfterWrite() |
||
104 | |||
105 | public function onBeforeWrite() |
||
119 | } |
||
120 |
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.