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 ElementalVersionedExtension extends VersionedDataObject |
||
|
|
|||
| 11 | { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @param array $fields |
||
| 15 | */ |
||
| 16 | public function updateSummaryFields(&$fields) |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Basic permissions, defaults to page perms where possible |
||
| 23 | */ |
||
| 24 | View Code Duplication | public function canView($member = null) |
|
| 35 | |||
| 36 | /** |
||
| 37 | * Basic permissions, defaults to page perms where possible |
||
| 38 | */ |
||
| 39 | View Code Duplication | public function canEdit($member = null) |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Basic permissions, defaults to page perms where possible |
||
| 52 | * Uses archive not delete so that current stage is respected |
||
| 53 | * i.e if a widget is not published, then it can be deleted by someone who |
||
| 54 | * doesn't have publishing permissions |
||
| 55 | */ |
||
| 56 | View Code Duplication | public function canDelete($member = null) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * Basic permissions, defaults to page perms where possible |
||
| 69 | */ |
||
| 70 | public function canCreate($member = null) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Handles unpublishing as VersionedDataObjects doesn't |
||
| 79 | * Modelled on SiteTree::doUnpublish |
||
| 80 | * Has to be applied here, rather than BaseElement so that goes against Widget |
||
| 81 | */ |
||
| 82 | public function doUnpublish() { |
||
| 103 | |||
| 104 | } |
||
| 105 |
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.