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 BlogPostSharedCategoriesExtension extends DataExtension |
||
|
|
|||
| 9 | { |
||
| 10 | private static $categories_checkboxes = true; |
||
| 11 | |||
| 12 | private static $tags_checkboxes = true; |
||
| 13 | /** |
||
| 14 | * overrules has_many method |
||
| 15 | * to return ALL categories |
||
| 16 | * |
||
| 17 | * @return DataList |
||
| 18 | */ |
||
| 19 | public function UsedCategories() |
||
| 23 | |||
| 24 | /** |
||
| 25 | * overrules has_many method |
||
| 26 | * to return ALL categories |
||
| 27 | * |
||
| 28 | * @return DataList |
||
| 29 | */ |
||
| 30 | public function UsedTags() |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Update Fields |
||
| 37 | * @return FieldList |
||
| 38 | */ |
||
| 39 | public function updateCMSFields(FieldList $fields) |
||
| 65 | } |
||
| 66 |
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.