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 |
||
| 5 | class CountryPrice_Translation extends DataObject |
||
|
|
|||
| 6 | { |
||
| 7 | |||
| 8 | private static $automatically_create_dummy_translations_for_products_and_productgroups = true; |
||
| 9 | |||
| 10 | private static $db = array( |
||
| 11 | 'Title' => 'Varchar(200)', |
||
| 12 | 'Content' => 'HTMLText', |
||
| 13 | 'WithoutTranslation' => 'Boolean' |
||
| 14 | ); |
||
| 15 | |||
| 16 | private static $field_labels = array( |
||
| 17 | 'Title' => 'Page Title', |
||
| 18 | 'Content' => 'Page Content', |
||
| 19 | 'EcommerceCountryID' => 'Country', |
||
| 20 | 'WithoutTranslation' => 'Price Difference Only' |
||
| 21 | ); |
||
| 22 | |||
| 23 | private static $has_one = array( |
||
| 24 | 'EcommerceCountry' => 'EcommerceCountry', |
||
| 25 | 'Parent' => 'SiteTree' |
||
| 26 | ); |
||
| 27 | |||
| 28 | private static $summary_fields = array( |
||
| 29 | 'EcommerceCountry.Name' => 'Country', |
||
| 30 | 'Title' => 'Title', |
||
| 31 | 'WithoutTranslation.Nice' => 'Price Difference Only' |
||
| 32 | ); |
||
| 33 | |||
| 34 | private static $casting = array( |
||
| 35 | 'Link' => 'Varchar' |
||
| 36 | ); |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | private static $locale_get_parameter = 'ecomlocale'; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Standard SS variable. |
||
| 45 | * |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | private static $singular_name = 'Translation'; |
||
| 49 | public function i18n_singular_name() |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Standard SS variable. |
||
| 56 | * |
||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | private static $plural_name = 'Translations'; |
||
| 60 | public function i18n_plural_name() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * CMS Fields |
||
| 67 | * @return FieldList |
||
| 68 | */ |
||
| 69 | public function getCMSFields() |
||
| 94 | |||
| 95 | public function canCreate($member = null) |
||
| 102 | |||
| 103 | public function canEdit($member = null) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * {@inheritdoc} |
||
| 110 | */ |
||
| 111 | protected function validate() |
||
| 133 | |||
| 134 | /** |
||
| 135 | * 'PageField' => 'Title' |
||
| 136 | * 'TranslationField' => 'Title' |
||
| 137 | * |
||
| 138 | * @return ArrayList |
||
| 139 | */ |
||
| 140 | public function FieldsToReplace() |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @return string |
||
| 165 | */ |
||
| 166 | public function Link() |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @return string |
||
| 173 | */ |
||
| 174 | public function getLink() |
||
| 182 | |||
| 183 | public function requireDefaultRecords() |
||
| 232 | |||
| 233 | } |
||
| 234 |
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.