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 $dependencies = array( |
||
| 11 | 'CountryURLProvider' => '%$CountryURLProvider', |
||
| 12 | ); |
||
| 13 | |||
| 14 | /** |
||
| 15 | * automatically populated by the dependency manager. |
||
| 16 | * |
||
| 17 | * @var CountryURLProvider |
||
| 18 | */ |
||
| 19 | public $CountryURLProvider = null; |
||
| 20 | |||
| 21 | private static $db = array( |
||
| 22 | 'Title' => 'Varchar(200)', |
||
| 23 | 'UseOriginalTitle' => 'Boolean', |
||
| 24 | 'Content' => 'HTMLText', |
||
| 25 | 'UseOriginalContent' => 'Boolean', |
||
| 26 | 'WithoutTranslation' => 'Boolean' |
||
| 27 | ); |
||
| 28 | |||
| 29 | private static $field_labels = array( |
||
| 30 | 'Title' => 'Page Title', |
||
| 31 | 'Content' => 'Page Content', |
||
| 32 | 'EcommerceCountryID' => 'Country', |
||
| 33 | 'WithoutTranslation' => 'Price Difference Only' |
||
| 34 | ); |
||
| 35 | |||
| 36 | private static $has_one = array( |
||
| 37 | 'EcommerceCountry' => 'EcommerceCountry', |
||
| 38 | 'Parent' => 'SiteTree' |
||
| 39 | ); |
||
| 40 | |||
| 41 | private static $summary_fields = array( |
||
| 42 | 'EcommerceCountry.Name' => 'Country', |
||
| 43 | 'Title' => 'Title', |
||
| 44 | 'WithoutTranslation.Nice' => 'Price Difference Only' |
||
| 45 | ); |
||
| 46 | |||
| 47 | private static $casting = array( |
||
| 48 | 'Link' => 'Varchar' |
||
| 49 | ); |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | private static $locale_get_parameter = 'ecomlocale'; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Standard SS variable. |
||
| 58 | * |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | private static $singular_name = 'Translation'; |
||
| 62 | public function i18n_singular_name() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Standard SS variable. |
||
| 69 | * |
||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | private static $plural_name = 'Translations'; |
||
| 73 | public function i18n_plural_name() |
||
| 77 | |||
| 78 | public static function get_country_url_provider() |
||
| 83 | |||
| 84 | /** |
||
| 85 | * CMS Fields |
||
| 86 | * @return FieldList |
||
| 87 | */ |
||
| 88 | public function getCMSFields() |
||
| 140 | |||
| 141 | public function canCreate($member = null) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * {@inheritdoc} |
||
| 151 | */ |
||
| 152 | protected function validate() |
||
| 174 | |||
| 175 | /** |
||
| 176 | * 'PageField' => 'Title' |
||
| 177 | * 'TranslationField' => 'Title' |
||
| 178 | * |
||
| 179 | * @return ArrayList |
||
| 180 | */ |
||
| 181 | public function FieldsToReplace() |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @return string |
||
| 212 | */ |
||
| 213 | public function Link() |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @return string |
||
| 220 | */ |
||
| 221 | public function getLink() |
||
| 235 | |||
| 236 | public function requireDefaultRecords() |
||
| 287 | |||
| 288 | } |
||
| 289 |
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.