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 ElementList extends BaseElement |
||
|
|||
9 | { |
||
10 | |||
11 | private static $db = array( |
||
12 | 'ListDescription' => 'HTMLText' |
||
13 | ); |
||
14 | |||
15 | private static $has_many = array( |
||
16 | 'Elements' => 'BaseElement' |
||
17 | ); |
||
18 | |||
19 | private static $duplicate_relations = array( |
||
20 | 'Elements' |
||
21 | ); |
||
22 | |||
23 | private static $extensions = array( |
||
24 | 'ElementPublishChildren' |
||
25 | ); |
||
26 | |||
27 | private static $title = "Element List Element"; |
||
28 | |||
29 | private static $description = "Orderable list of elements"; |
||
30 | |||
31 | protected $enable_title_in_template = true; |
||
32 | |||
33 | public function getCMSFields() |
||
88 | |||
89 | /** |
||
90 | * Used in template instead of {@link Widgets()} to wrap each widget in its |
||
91 | * controller, making it easier to access and process form logic and |
||
92 | * actions stored in {@link WidgetController}. |
||
93 | * |
||
94 | * @return SS_List - Collection of {@link WidgetController} instances. |
||
95 | */ |
||
96 | public function WidgetControllers() { |
||
108 | } |
||
109 |
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.