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 |
||
6 | class ElementalWidgetExtension extends DataExtension |
||
|
|||
7 | { |
||
8 | |||
9 | /** |
||
10 | * @param array $fields |
||
11 | */ |
||
12 | public function updateSummaryFields(&$fields) |
||
16 | |||
17 | /** |
||
18 | * Basic permissions, defaults to page perms where possible |
||
19 | */ |
||
20 | View Code Duplication | public function canView($member = null) |
|
30 | |||
31 | /** |
||
32 | * Basic permissions, defaults to page perms where possible |
||
33 | */ |
||
34 | View Code Duplication | public function canEdit($member = null) |
|
44 | |||
45 | /** |
||
46 | * Basic permissions, defaults to page perms where possible |
||
47 | * Uses archive not delete so that current stage is respected |
||
48 | * i.e if a widget is not published, then it can be deleted by someone who |
||
49 | * doesn't have publishing permissions |
||
50 | */ |
||
51 | View Code Duplication | public function canDelete($member = null) |
|
61 | |||
62 | /** |
||
63 | * Basic permissions, defaults to page perms where possible |
||
64 | */ |
||
65 | public function canCreate($member = null) |
||
71 | |||
72 | /** |
||
73 | * Handles unpublishing as VersionedDataObjects doesn't |
||
74 | * Modelled on SiteTree::doUnpublish |
||
75 | * Has to be applied here, rather than BaseElement so that goes against Widget |
||
76 | */ |
||
77 | public function doUnpublish() { |
||
98 | |||
99 | } |
||
100 |
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.