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 |
||
| 9 | class SilverstripeColumnsPageControllerExtension extends Extension |
||
|
|
|||
| 10 | { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @return bool |
||
| 14 | */ |
||
| 15 | View Code Duplication | function HasFullWidthContent() |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @return bool |
||
| 30 | */ |
||
| 31 | function HasSideBar() |
||
| 50 | |||
| 51 | |||
| 52 | /** |
||
| 53 | * @param boolean $asClassName |
||
| 54 | * |
||
| 55 | * @return string | int |
||
| 56 | */ |
||
| 57 | function NumberOfColumns($asClassName = true) |
||
| 81 | |||
| 82 | |||
| 83 | /** |
||
| 84 | * returns a data list of items that have been edited last - up to one day ago. |
||
| 85 | * This ensures that we do not show stuff we have just fixed up... |
||
| 86 | * @return DataList |
||
| 87 | */ |
||
| 88 | function RecentlyUpdated($limit = 5) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @return null | DataList |
||
| 109 | */ |
||
| 110 | function InThisSection() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Siblings |
||
| 123 | * @return null | DataList |
||
| 124 | */ |
||
| 125 | function AlsoSee() |
||
| 139 | |||
| 140 | } |
||
| 141 |
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.