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 EcommerceMailchimpSignupMemberExtension extends DataExtension |
||
|
|
|||
| 6 | { |
||
| 7 | private static $db = array( |
||
| 8 | 'SignedUpToMailchimp' => "Boolean" |
||
| 9 | ); |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Store the user in MailChimp |
||
| 13 | * @param array $mergeVars |
||
| 14 | * @return Boolean |
||
| 15 | */ |
||
| 16 | public function subscribeToMailchimp($mergeVars = array()) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * |
||
| 45 | * @return bool |
||
| 46 | */ |
||
| 47 | public function existsOnMailchimp() |
||
| 70 | |||
| 71 | /** |
||
| 72 | * |
||
| 73 | * @return bool |
||
| 74 | */ |
||
| 75 | public function updateOnMailchimp() |
||
| 98 | |||
| 99 | /** |
||
| 100 | * casted variable |
||
| 101 | */ |
||
| 102 | private static $_mailchimp_api = null; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @return MailChimp |
||
| 106 | */ |
||
| 107 | protected function getMailChimpAPI() |
||
| 117 | } |
||
| 118 |
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.